package http import ( "context" "encoding/json" "mic-wallet/common" "mic-wallet/server/core" "net/http" ) type ApiDependencies struct { *core.BlocksCreator } /* / -- node info /txs -- add/get txs /blocks -- get/blocks /blocks/current -- get current block info */ func NewApi(ctx context.Context, d ApiDependencies, baseRoute string) *http.ServeMux { if baseRoute == "" { baseRoute = "/" } mux := http.NewServeMux() /* */ mux.HandleFunc(baseRoute, func(w http.ResponseWriter, r *http.Request) { if r.URL.Path != "/" { w.WriteHeader(http.StatusNotFound) return } if r.Method != http.MethodGet { w.WriteHeader(http.StatusMethodNotAllowed) return } data, _ := json.Marshal(common.NodeInfo{ NodeVersion: common.VersionNumberStr, }) w.Write(data) w.WriteHeader(http.StatusOK) }) return mux }