changed lib removed map_args, project_dir debug; changed render added get_template; small changes to api,manager due to function delition; big change to web split listen and serve for server log and routing through switch-case

This commit is contained in:
2025-10-13 20:38:21 +00:00
parent 3820bc399b
commit 960d9e2ff8
6 changed files with 86 additions and 43 deletions

View File

@ -5,21 +5,35 @@ import (
"api_manager/web/manager"
"api_manager/web/render"
"fmt"
"net"
"net/http"
)
func Server() {
http.HandleFunc("/", main_page)
http.HandleFunc("/mgr/add", manager.Add_api)
http.HandleFunc("/mgr/show", manager.Render_apis)
http.HandleFunc("/api/", api.Get_api)
http.ListenAndServe(":8090", nil)
l, err := net.Listen("tcp", ":8090")
if err == nil {
fmt.Println("Listening on port 8090")
}
http.Serve(l, http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
switch r.URL.Path {
case "/":
main_page(w,r);
case "/mgr/add":
manager.Add_api(w,r)
case "/mgr/show":
manager.Render_apis(w,r)
case "/api/":
api.Get_api(w,r)
default:
fmt.Fprint(w,"Not Found")
return
}
}))
}
// wellcoming main web page
func main_page(w http.ResponseWriter, req *http.Request) {
templ := map[string]string{"welcome_message": "hello world! this is api server with easy web menagment"}
templ := map[string]string{"welcome_message": "hello world! this is api server with easy web menagment","template_title":"main page"}
fmt.Fprint(w, render.Put_vars_to_template(render.Template_of_part("main"), templ))
}