Changed the structure of the whole application, should be no changes to functionality.
This commit is contained in:
32
pkg/api/index.go
Normal file
32
pkg/api/index.go
Normal file
@@ -0,0 +1,32 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"music-server/pkg/helpers"
|
||||
"music-server/pkg/server"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func IndexHandler(w http.ResponseWriter, r *http.Request) {
|
||||
helpers.SetCorsAndNoCacheHeaders(&w, r)
|
||||
|
||||
if r.URL.Path == "/version" {
|
||||
w.Header().Add("Content-Type", "application/json")
|
||||
|
||||
history := server.GetVersionHistory()
|
||||
_ = json.NewEncoder(w).Encode(history)
|
||||
|
||||
} else if r.URL.Path == "/docs" {
|
||||
http.ServeFile(w, r, "./docs/swagger.yaml")
|
||||
|
||||
} else if r.URL.Path == "/" {
|
||||
_, err := fmt.Fprint(w, "Hello, World!!")
|
||||
if err != nil {
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
}
|
||||
} else {
|
||||
http.NotFound(w, r)
|
||||
return
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user