Added dispatching to cargo indices
This commit is contained in:
parent
36e9ebeb87
commit
227e9fed59
55
main.go
55
main.go
@ -10,19 +10,31 @@ import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
type config struct {
|
||||
Listen string `json:"listen"`
|
||||
Domain string `json:"domain"`
|
||||
Organizations []string `json:"organizations"`
|
||||
type listeners struct {
|
||||
Maven string `json:"maven"`
|
||||
Cargo string `json:"cargo"`
|
||||
}
|
||||
|
||||
func searcher(config *config, w http.ResponseWriter, r *http.Request) {
|
||||
type config struct {
|
||||
Listen listeners `json:"listen"`
|
||||
Domain string `json:"domain"`
|
||||
Organizations []string `json:"organizations"`
|
||||
}
|
||||
|
||||
func searcher(config *config, dst string, useGet bool, w http.ResponseWriter, r *http.Request) {
|
||||
for _, org := range config.Organizations {
|
||||
actualUrl := fmt.Sprintf(
|
||||
"https://%s/api/packages/%s/maven/%s",
|
||||
dst,
|
||||
config.Domain, org, strings.TrimLeft(r.URL.Path, "/"),
|
||||
)
|
||||
resp, err := http.Head(actualUrl)
|
||||
|
||||
var resp *http.Response
|
||||
var err error
|
||||
if useGet {
|
||||
resp, err = http.Get(actualUrl)
|
||||
} else {
|
||||
resp, err = http.Head(actualUrl)
|
||||
}
|
||||
if err != nil {
|
||||
w.WriteHeader(500)
|
||||
_, err := fmt.Fprintf(w, "%v", err)
|
||||
@ -97,8 +109,29 @@ func main() {
|
||||
return
|
||||
}
|
||||
|
||||
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
|
||||
searcher(&config, w, r)
|
||||
})
|
||||
log.Fatal(http.ListenAndServe(config.Listen, nil))
|
||||
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 {}
|
||||
}
|
||||
|
||||
@ -11,7 +11,10 @@ Merges several Gitea organizations' maven repositories to one path.
|
||||
- `organizations` - list of Gitea organizations which should be included to search
|
||||
```json
|
||||
{
|
||||
"listen": "localhost:49186",
|
||||
"listen": {
|
||||
"maven": "localhost:49186",
|
||||
"cargo": "localhost:49187"
|
||||
},
|
||||
"domain": "git.landgrafhomyak.ru",
|
||||
"organizations": [
|
||||
"xomrk",
|
||||
|
||||
Loading…
Reference in New Issue
Block a user