func Start() { if !g.Config().Http.Enabled { return } addr := g.Config().Http.Listen if addr == "" { return } //s := &http.Server{ // Addr: addr, // MaxHeaderBytes: 1 << 30, //} log.Println("https listening", addr) err := http.ListenAndServeTLS(addr, "cert.pem", "key.pem", nil) log.Fatalln(err) }
func configCommonRoutes() { http.HandleFunc("/health", func(w http.ResponseWriter, r *http.Request) { w.Write([]byte("ok")) }) http.HandleFunc("/version", func(w http.ResponseWriter, r *http.Request) { w.Write([]byte(g.VERSION)) }) http.HandleFunc("/workdir", func(w http.ResponseWriter, r *http.Request) { RenderDataJson(w, file.SelfDir()) }) http.HandleFunc("/config/reload", func(w http.ResponseWriter, r *http.Request) { if strings.HasPrefix(r.RemoteAddr, "127.0.0.1") { err := g.ParseConfig(g.ConfigFile) AutoRender(w, g.Config(), err) } else { w.Write([]byte("no privilege")) } }) }
func configTarballRoutes() { http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { auth := strings.SplitN(r.Header["Authorization"][0], " ", 2) if len(auth) != 2 || auth[0] != "Basic" { http.Error(w, "bad syntax", http.StatusBadRequest) return } payload, _ := base64.StdEncoding.DecodeString(auth[1]) pair := strings.SplitN(string(payload), ":", 2) if len(pair) != 2 || !Validate(pair[0], pair[1]) { http.Error(w, "authorization failed", http.StatusUnauthorized) return } http.FileServer(http.Dir(g.Config().TarballDir)).ServeHTTP(w, r) }) }