Skip to content

Commit

Permalink
refactor(all): cursorAI, test, ..
Browse files Browse the repository at this point in the history
  • Loading branch information
archmagece committed Oct 2, 2024
1 parent 48318de commit 854e2cc
Show file tree
Hide file tree
Showing 16 changed files with 76 additions and 61 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@
# dev
.env

# build
# build & generated
build/
/main
/proxynd
/coverage.out

# test
tmp/
Expand Down
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ setup:
mkdir -p ~/tmp/config
mkdir -p ~/tmp/storage
cp -r sample-conf/* ~/tmp/config/.
go install github.com/golangci/golangci-lint/cmd/[email protected]

docker-build:
@echo "Building..."
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# 프론신디
# 프록신디

## 지원기능

Expand All @@ -15,6 +15,8 @@
- [ ] 쩌 Repo 인증기능
- [ ] 이 리포 인증기능

- [ ] Storage Limit

## Install

### 설정
Expand Down
4 changes: 3 additions & 1 deletion configs/apt_mirror_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,7 @@ func TestAptMirrorConfig_ReadConfig(t *testing.T) {
cfg.ReadConfig()
fmt.Println(cfg)
assert.Equal(t, cfg.Path, "mirror/apt")
fmt.Println(helpers.ToStringYaml(cfg))
assert.Equal(t, len(cfg.Mirrors.Ubuntu), 2)
assert.Equal(t, len(cfg.Mirrors.Debian), 2)
fmt.Println(helpers.YamlToString(cfg))
}
2 changes: 1 addition & 1 deletion configs/apt_proxy_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ func TestAptProxyConfig_ReadConfig(t *testing.T) {
cfg.ReadConfig()
fmt.Println(cfg)
assert.Equal(t, cfg.Path, "proxy/apt")
fmt.Println(helpers.ToStringYaml(cfg))
fmt.Println(helpers.YamlToString(cfg))
}
15 changes: 11 additions & 4 deletions configs/global_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,19 @@ import (
"testing"
)

func TestRead_GlobalConfig(t *testing.T) {
os.Setenv("CONFIG_DIR", "../sample-conf/")
os.Setenv("STORAGE_DIR", "../sample-conf/")
func TestReadConfig_GlobalConfig(t *testing.T) {
var err error
err = os.Setenv("CONFIG_DIR", "../sample-conf/")
if err != nil {
return
}
err = os.Setenv("STORAGE_DIR", "../sample-conf/")
if err != nil {
return
}
cfg := GlobalConfig{}
cfg.ReadConfig()
assert.Equal(t, cfg.Cache.TTL, 3600)
//assert.Equal(t, cfg.ConfigDir, "~/tmp/config")
fmt.Println(helpers.ToStringYaml(cfg))
fmt.Println(helpers.YamlToString(cfg))
}
2 changes: 1 addition & 1 deletion configs/maven_mirror_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ func TestMavenConfig_MavenMirror(t *testing.T) {
cfg.ReadConfig()
//fmt.Println(cfg)
assert.Equal(t, cfg.Path, "mirror/maven")
fmt.Println(helpers.ToStringYaml(cfg))
fmt.Println(helpers.YamlToString(cfg))
}
7 changes: 4 additions & 3 deletions configs/maven_proxy_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func TestMavenConfig_MavenProxy(t *testing.T) {
cfg.ReadConfig()
//fmt.Println(cfg)
assert.Equal(t, cfg.Path, "proxy/maven")
fmt.Println(helpers.ToStringYaml(cfg))
fmt.Println(helpers.YamlToString(cfg))
}

func TestYamlMake(t *testing.T) {
Expand Down Expand Up @@ -62,15 +62,16 @@ func TestYamlMake(t *testing.T) {
}

func TestYaml(t *testing.T) {
yamlFile, err := os.ReadFile("../configs/maven-proxy.yaml")
yamlFile, err := os.ReadFile("../sample-conf/maven-proxy.yaml")
if err != nil {
log.Printf("yamlFile.Get err #%v ", err)
}
fmt.Println(string(yamlFile))
mavenConfig := MavenProxyConfig{
Proxies: []MavenProxyServer{},
}
err = yaml.Unmarshal(yamlFile, mavenConfig)
err = yaml.Unmarshal(yamlFile, &mavenConfig)
//fmt.Println(helpers.YamlToString(mavenConfig))
if err != nil {
log.Fatalf("Unmarshal: %v", err)
}
Expand Down
7 changes: 0 additions & 7 deletions configs/vagrant_proxy_config_test.go

This file was deleted.

8 changes: 7 additions & 1 deletion handlers/proxy/apt_proxy_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"io"
"log"
"net/http"
"net/url"
"os"
"path"
"path/filepath"
Expand Down Expand Up @@ -56,7 +57,12 @@ func AptProxy(c *gin.Context) {
proxy := config.Proxies[pathOs]
for s, server := range proxy {
fmt.Printf("for moon %d\n", s)
resp, err := http.Get(helpers.JoinURL(server.URL, requestPath))
result, err := url.JoinPath(server.URL, requestPath)
if err != nil {
log.Fatal(err)
return
}
resp, err := http.Get(result)
if err != nil {
log.Fatal(err)
return
Expand Down
20 changes: 17 additions & 3 deletions handlers/proxy/docker_proxy_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"io"
"log"
"net/http"
"net/url"
"os"
"path"
"path/filepath"
Expand Down Expand Up @@ -41,13 +42,22 @@ func DockerProxy(c *gin.Context) {
//log.Fatal(err)
//return
}
defer out.Close()
defer func() {
if err := out.Close(); err != nil {
log.Printf("Error closing file: %v", err)
}
}()

// Get the data
//proxy := config.Proxies["docker"]
for s, server := range config.Proxies {
log.Printf("Trying server %d: %s\n", s, server.Url)
resp, err := http.Get(helpers.JoinURL(server.Url, imageName, tag))
result, err := url.JoinPath(server.Url, imageName, tag)
if err != nil {
log.Fatal(err)
return
}
resp, err := http.Get(result)
if err != nil {
log.Fatal(err)
return
Expand All @@ -62,7 +72,11 @@ func DockerProxy(c *gin.Context) {
log.Fatal(err)
return
}
resp.Body.Close()
err = resp.Body.Close()
if err != nil {
log.Fatal(err)
return
}
break
}
}
Expand Down
8 changes: 7 additions & 1 deletion handlers/proxy/maven_proxy_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"io"
"log"
"net/http"
"net/url"
"os"
"path"
"path/filepath"
Expand Down Expand Up @@ -72,7 +73,12 @@ func MavenProxy(c *gin.Context) {

for s, server := range config.Proxies {
fmt.Printf("for moon %d\n", s)
resp, err := http.Get(helpers.JoinURL(server.Url, requestPath))
result, err := url.JoinPath(server.Url, requestPath)
if err != nil {
log.Fatal(err)
return
}
resp, err := http.Get(result)
if err != nil {
log.Fatal(err)
return
Expand Down
21 changes: 0 additions & 21 deletions helpers/url_helper.go
Original file line number Diff line number Diff line change
@@ -1,22 +1 @@
package helpers

import (
"fmt"
"path"
"strings"
)

//func JoinURL1(host string, paths ...string) string {
// u, err := url.Parse(host)
// if err != nil {
// panic(err)
// }
// u.Path = path.Join(u.Path, path.Join(paths...))
// s := u.String()
// return s
//}

func JoinURL(base string, paths ...string) string {
p := path.Join(paths...)
return fmt.Sprintf("%s/%s", strings.TrimRight(base, "/"), strings.TrimLeft(p, "/"))
}
15 changes: 0 additions & 15 deletions helpers/url_helper_test.go
Original file line number Diff line number Diff line change
@@ -1,16 +1 @@
package helpers

import (
"fmt"
"testing"
)

//func TestJoinURL1(t *testing.T) {
// result1 := JoinURL("http://naver.com/", "/download")
// fmt.Println(result1)
//}

func TestJoinURL(t *testing.T) {
result1 := JoinURL("http://naver.com/", "/download")
fmt.Println(result1)
}
2 changes: 1 addition & 1 deletion helpers/yaml_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func ReadYaml(path string, out interface{}) {
log.Printf("read config success %s \n", out)
}

func ToStringYaml(out interface{}) string {
func YamlToString(out interface{}) string {
d, err := yaml.Marshal(out)
if err != nil {
log.Fatalf("error: %v", err)
Expand Down
18 changes: 18 additions & 0 deletions sample-conf/apt-mirror.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,21 @@ mirrors:
url: http://ftp.debian.org/debian
kakao:
url: http://mirror.kakao.com/debian
parrot:
official:
url: http://deb.parrot.sh/parrot
kakao:
url: http://mirror.kakao.com/parrot
linuxmint:
official:
url: http://packages.linuxmint.com
kakao:
url: http://mirror.kakao.com/linuxmint
kali:
official:
url: http://http.kali.org/kali
raspbian:
official:
url: http://archive.raspbian.org/raspbian
kakao:
url: http://mirror.kakao.com/raspbian

0 comments on commit 854e2cc

Please sign in to comment.