diff --git a/cmd/api/get-content-types.go b/cmd/api/get-content-types.go new file mode 100644 index 0000000..09ccc9c --- /dev/null +++ b/cmd/api/get-content-types.go @@ -0,0 +1,15 @@ +package api + +import ( + "github.com/Dobefu/csb/cmd/cs_sdk" +) + +func GetContentTypes() (map[string]interface{}, error) { + data, err := cs_sdk.Request("content_types", "GET", nil) + + if err != nil { + return nil, err + } + + return data, nil +} diff --git a/cmd/server/handle-routes.go b/cmd/server/handle-routes.go index 0921f08..0123de2 100644 --- a/cmd/server/handle-routes.go +++ b/cmd/server/handle-routes.go @@ -16,6 +16,7 @@ func HandleRoutes(mux *http.ServeMux, apiPath string) { apiRoute(mux, apiPath, "/get-entry-by-url", "GET", v1.GetEntryByUrl) apiRoute(mux, apiPath, "/get-entry-by-uid", "GET", v1.GetEntryByUid) + apiRoute(mux, apiPath, "/content-types", "GET", v1.GetContentTypes) } func apiRoute( diff --git a/cmd/server/routes/v1/get-content-types.go b/cmd/server/routes/v1/get-content-types.go new file mode 100644 index 0000000..9fbff83 --- /dev/null +++ b/cmd/server/routes/v1/get-content-types.go @@ -0,0 +1,28 @@ +package v1 + +import ( + "encoding/json" + "fmt" + "net/http" + + "github.com/Dobefu/csb/cmd/api" + "github.com/Dobefu/csb/cmd/server/utils" +) + +func GetContentTypes(w http.ResponseWriter, r *http.Request) { + output, err := api.GetContentTypes() + + if err != nil { + utils.PrintError(w, err, false) + return + } + + json, err := json.Marshal(output["content_types"]) + + if err != nil { + utils.PrintError(w, err, true) + return + } + + fmt.Fprint(w, string(json)) +}