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:
28
web/web.go
28
web/web.go
@ -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))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user