package api // package for reading and working with the storage file of the api's // saving, loading, handling the api requests import ( "api_manager/lib" "encoding/json" "io/ioutil" "net/http" "os" "strings" ) // api manipulation function func Apis() map[string]interface{} { return get_apis() } // return the value of api by name func Get_api(w http.ResponseWriter, req *http.Request) { apis := Apis() str := strings.Replace(string(req.RequestURI), "/api/", "", 1) jData, err := json.Marshal(apis[str]) lib.Handle_err(err, map[string]string{}) w.Header().Set("Content-Type", "application/json") w.Write(jData) } // reding the api storage file. returning map value like map[main:{sub:sub}] func get_apis() map[string]interface{} { jsonFile, err := os.Open("web/api/apis") lib.Handle_err(err, map[string]string{}) defer jsonFile.Close() byteValue, _ := ioutil.ReadAll(jsonFile) var result map[string]interface{} json.Unmarshal([]byte(byteValue), &result) return result }