Working daemon with hardcoded params
This commit is contained in:
commit
9f4eef0515
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
/.idea/
|
||||
65
main.go
Normal file
65
main.go
Normal file
@ -0,0 +1,65 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"net/http"
|
||||
"net/http/httputil"
|
||||
"strings"
|
||||
)
|
||||
|
||||
const DOMAIN = "git.landgrafhomyak.ru"
|
||||
|
||||
var ORGS_LIST = []string{"Multitasking", "LanguageUtilities", "xomrk"}
|
||||
|
||||
func searcher(w http.ResponseWriter, r *http.Request) {
|
||||
for _, org := range ORGS_LIST {
|
||||
actualUrl := fmt.Sprintf(
|
||||
"https://%s/api/packages/%s/maven/%s",
|
||||
DOMAIN, org, strings.TrimLeft(r.URL.Path, "/"),
|
||||
)
|
||||
resp, err := http.Head(actualUrl)
|
||||
if err != nil {
|
||||
w.WriteHeader(500)
|
||||
_, err := fmt.Fprintf(w, "%v", err)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
return
|
||||
}
|
||||
switch resp.StatusCode {
|
||||
case 200:
|
||||
w.Header().Set("Location", actualUrl)
|
||||
w.WriteHeader(307)
|
||||
return
|
||||
case 404:
|
||||
fallthrough
|
||||
case 403:
|
||||
continue
|
||||
case 502:
|
||||
fallthrough
|
||||
case 503:
|
||||
w.WriteHeader(503)
|
||||
return
|
||||
default:
|
||||
w.WriteHeader(500)
|
||||
rawResp, err := httputil.DumpResponse(resp, true)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
return
|
||||
}
|
||||
_, err = w.Write(rawResp)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
return
|
||||
}
|
||||
return
|
||||
}
|
||||
}
|
||||
w.WriteHeader(404)
|
||||
}
|
||||
|
||||
func main() {
|
||||
http.HandleFunc("/", searcher)
|
||||
log.Fatal(http.ListenAndServe("localhost:49186", nil))
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user