While you have multiple pages (or functions)…


In my case, I’ll have basic following pages:

Nothing fancy, nothing new, just code here:

package main

import (
   "encoding/json"
   "net/http"
)

func index(w http.ResponseWriter, r *http.Request)  {
   mapindex := map[string]interface{}{"tittle": "iptables", "region_name": "region_name", "region_number": 52, "iptables":"172.26.52.11"}

   json.NewEncoder(w).Encode(mapindex)
}

func inbound(w http.ResponseWriter, r *http.Request)  {
   mapinbound := map[string]interface{}{"tittle":"inbound", "region_name": "region_name", "region_number": 52, "inbound rules": "inbound"}

   json.NewEncoder(w).Encode(mapinbound)
}

func outbound(w http.ResponseWriter, r *http.Request) {
   mapinbound := map[string]interface{}{"tittle":"inbound", "region_name": "region_name", "region_number": 52, "inbound rules": "outbound"}

   json.NewEncoder(w).Encode(mapinbound)
}

func main() {
   http.HandleFunc("/", index)
   http.HandleFunc("/inbound", inbound)
   http.HandleFunc("/outbound", outbound)

   http.ListenAndServe(":8080", nil)
}

Will do bash run tomorrow…

R