Compare commits

..

No commits in common. "master" and "v0.1" have entirely different histories.
master ... v0.1

2 changed files with 13 additions and 64 deletions

53
main.go
View File

@ -10,31 +10,19 @@ import (
"strings"
)
type listeners struct {
Maven string `json:"maven"`
Cargo string `json:"cargo"`
}
type config struct {
Listen listeners `json:"listen"`
Domain string `json:"domain"`
Organizations []string `json:"organizations"`
Listen string `json:"listen"`
Domain string `json:"domain"`
Organizations []string `json:"organizations"`
}
func searcher(config *config, dst string, useGet bool, w http.ResponseWriter, r *http.Request) {
func searcher(config *config, w http.ResponseWriter, r *http.Request) {
for _, org := range config.Organizations {
actualUrl := fmt.Sprintf(
dst,
"https://%s/api/packages/%s/maven/%s",
config.Domain, org, strings.TrimLeft(r.URL.Path, "/"),
)
var resp *http.Response
var err error
if useGet {
resp, err = http.Get(actualUrl)
} else {
resp, err = http.Head(actualUrl)
}
resp, err := http.Head(actualUrl)
if err != nil {
w.WriteHeader(500)
_, err := fmt.Fprintf(w, "%v", err)
@ -109,29 +97,8 @@ func main() {
return
}
go func() {
dispatcher := http.NewServeMux()
dispatcher.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
searcher(&config, "https://%s/api/packages/%s/maven/%s", false, w, r)
})
server := http.Server{
Addr: config.Listen.Maven,
Handler: dispatcher,
}
log.Fatal(server.ListenAndServe())
}()
go func() {
dispatcher := http.NewServeMux()
dispatcher.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
searcher(&config, "https://%s/api/packages/%s/cargo/%s", true, w, r)
})
server := http.Server{
Addr: config.Listen.Cargo,
Handler: dispatcher,
}
log.Fatal(server.ListenAndServe())
}()
select {}
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
searcher(&config, w, r)
})
log.Fatal(http.ListenAndServe(config.Listen, nil))
}

View File

@ -1,8 +1,8 @@
Merges several Gitea organizations' maven/cargo repositories to one path.
Merges several Gitea organizations' maven repositories to one path.
## usage
```shell
./maven-on-gitea-redirector-v0.2 config.json
./maven-on-gitea-redirector-v0.1 config.json
```
## config
@ -11,10 +11,7 @@ Merges several Gitea organizations' maven/cargo repositories to one path.
- `organizations` - list of Gitea organizations which should be included to search
```json
{
"listen": {
"maven": "localhost:49186",
"cargo": "localhost:49187"
},
"listen": "localhost:49186",
"domain": "git.landgrafhomyak.ru",
"organizations": [
"xomrk",
@ -22,19 +19,4 @@ Merges several Gitea organizations' maven/cargo repositories to one path.
"LanguageUtilities"
]
}
```
## Additional steps
### Cargo ([sparse](https://doc.rust-lang.org/cargo/reference/registry-index.html#index-format))
Client checks first `/config.json`, which contains paths to API roots. Since each organization has its own config,
it should be manually redirected (by `nginx` etc.) to custom config which contains paths to wrapper
instead of org registry:
```json
{
"dl": "https://cargo.landgrafhomyak.ru/api/v1/crates/",
"api": "https://cargo.landgrafhomyak.ru/",
"auth-required": false
}
```