-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0255a80
commit b6e7570
Showing
18 changed files
with
276 additions
and
224 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package config | ||
|
||
import ( | ||
"fmt" | ||
"gopkg.in/yaml.v3" | ||
"io/ioutil" | ||
"log" | ||
) | ||
|
||
type MavenServer struct { | ||
Id string `yaml:"id"` | ||
Name string `yaml:"name"` | ||
Url string `yaml:"url"` | ||
Description string `yaml:"description"` | ||
} | ||
|
||
type MavenConfig struct { | ||
Server map[string]MavenServer `yaml:"server"` | ||
} | ||
|
||
type DownloadService struct { | ||
MavenConfig | ||
} | ||
|
||
func (ds *DownloadService) DownloadProxy(path string) (MavenConfig, error) { | ||
// cache - no expire | ||
yamlFile, err := ioutil.ReadFile("config/maven-proxy-public.yaml") | ||
if err != nil { | ||
log.Printf("read config err #%v ", err) | ||
} | ||
fmt.Println(yamlFile) | ||
mavenConfig := MavenConfig{ | ||
Server: map[string]MavenServer{}, | ||
} | ||
err = yaml.Unmarshal(yamlFile, mavenConfig) | ||
fmt.Println(mavenConfig) | ||
if err != nil { | ||
log.Fatalf("Unmarshal: %v", err) | ||
} | ||
fmt.Printf("config %s \n", mavenConfig) | ||
return mavenConfig, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package config | ||
|
||
import ( | ||
"fmt" | ||
"gopkg.in/yaml.v3" | ||
"io/ioutil" | ||
"log" | ||
"os" | ||
"testing" | ||
) | ||
|
||
func TestYamlMake(t *testing.T) { | ||
mavenConfig := MavenConfig{} | ||
mavenConfig.Server = map[string]MavenServer{ | ||
"centeral": { | ||
Id: "maven-center", | ||
Name: "Center", | ||
Url: "https://repo.maven.com", | ||
Description: "desc1", | ||
}, | ||
"jcenter": { | ||
Id: "jcenter-center", | ||
Name: "JCenter", | ||
Url: "https://repo.jmaven.com", | ||
Description: "desc2", | ||
}, | ||
"google": { | ||
Url: "https://repo.jmaven.com", | ||
Description: "desc2", | ||
}, | ||
"spring-release": { | ||
Name: "springrelease", | ||
Url: "https://repo.jmaven.com", | ||
}, | ||
} | ||
yamlFile, err := yaml.Marshal(mavenConfig) | ||
if err != nil { | ||
fmt.Println("errrrr write") | ||
} | ||
ioutil.WriteFile("../config/maven-tmp.yaml", yamlFile, os.ModeAppend) | ||
fmt.Println(string(yamlFile)) | ||
|
||
mavenConfig2 := MavenConfig{ | ||
Server: map[string]MavenServer{}, | ||
} | ||
err = yaml.Unmarshal(yamlFile, mavenConfig2) | ||
fmt.Println(mavenConfig2) | ||
} | ||
|
||
func TestYaml(t *testing.T) { | ||
|
||
yamlFile, err := ioutil.ReadFile("../config/maven-proxy-public.yaml") | ||
if err != nil { | ||
log.Printf("yamlFile.Get err #%v ", err) | ||
} | ||
fmt.Println(string(yamlFile)) | ||
mavenConfig := MavenConfig{ | ||
Server: map[string]MavenServer{}, | ||
} | ||
err = yaml.Unmarshal(yamlFile, mavenConfig) | ||
if err != nil { | ||
log.Fatalf("Unmarshal: %v", err) | ||
} | ||
|
||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package controllers | ||
|
||
import ( | ||
u "dohoarding/apiHelpers" | ||
config2 "dohoarding/config" | ||
"dohoarding/utils" | ||
"fmt" | ||
"github.com/gin-gonic/gin" | ||
"io" | ||
"log" | ||
"net/http" | ||
"os" | ||
"path" | ||
"path/filepath" | ||
) | ||
|
||
func Maven(c *gin.Context) { | ||
log.Printf("Access proxy maven\n") | ||
var downloadService config2.DownloadService | ||
|
||
requestPath := c.Param("path") | ||
config, err := downloadService.DownloadProxy(requestPath) | ||
if err != nil { | ||
u.Respond(c.Writer, u.Message(1, "Invalid request")) | ||
return | ||
} | ||
|
||
// Create the file | ||
dirpath := filepath.Dir(path.Join("d:/tmp/cachedir" + requestPath)) | ||
filename := filepath.Base(requestPath) | ||
os.MkdirAll(dirpath, os.ModePerm) | ||
out, err := os.Create(path.Join("d:/tmp/cachedir" + requestPath)) | ||
//out, err := os.Create("d:/tmp/cachedir/aaa/bbb") | ||
if err != nil { | ||
panic(err) | ||
return | ||
} | ||
defer out.Close() | ||
|
||
// Get the data | ||
fmt.Println(len(config.Server)) | ||
for s, server := range config.Server { | ||
fmt.Printf("for moon %s\n", s) | ||
resp, err := http.Get(utils.JoinURL(server.Url, requestPath)) | ||
if err != nil { | ||
log.Fatal(err) | ||
return | ||
} | ||
//fmt.Println(resp.Header) | ||
fmt.Println(resp.StatusCode) | ||
// Writer the body to file | ||
_, err = io.Copy(out, resp.Body) | ||
if err != nil { | ||
log.Fatal(err) | ||
return | ||
} | ||
resp.Body.Close() | ||
break | ||
} | ||
|
||
c.Header("Content-Description", "File Transfer") | ||
c.Header("Content-Transfer-Encoding", "binary") | ||
c.Header("Content-Disposition", "attachment; filename="+filename) | ||
c.Header("Content-Type", "application/octet-stream") | ||
c.File("d:/tmp/cachedir" + requestPath) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.