Added login, some auth methods and a couple routes with no implementation
This commit is contained in:
parent
f76aa74179
commit
f1cae0d660
79 changed files with 8971 additions and 10 deletions
10
server/api/auth.go
Normal file
10
server/api/auth.go
Normal file
|
@ -0,0 +1,10 @@
|
|||
package api
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func (a *API) Login(w http.ResponseWriter, r *http.Request) {
|
||||
fmt.Fprintf(w, "FROM API")
|
||||
}
|
9
server/api/user.go
Normal file
9
server/api/user.go
Normal file
|
@ -0,0 +1,9 @@
|
|||
package api
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func (a *API) CreateUser(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
}
|
43
server/api/utils.go
Normal file
43
server/api/utils.go
Normal file
|
@ -0,0 +1,43 @@
|
|||
package api
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
|
||||
"github.com/rs/zerolog/log"
|
||||
)
|
||||
|
||||
type Body map[string]interface{}
|
||||
|
||||
func ParseBody(r *http.Request) *Body {
|
||||
var body Body
|
||||
_ = json.NewDecoder(r.Body).Decode(&body)
|
||||
defer r.Body.Close()
|
||||
return &body
|
||||
}
|
||||
|
||||
func (b *Body) String(name string) string {
|
||||
if res, ok := (*b)[name].(string); ok {
|
||||
return res
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func (b *Body) Int(name string) int {
|
||||
if res, ok := (*b)[name].(int); ok {
|
||||
return res
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func JSON(w http.ResponseWriter, data interface{}, statusCode int) {
|
||||
b, err := json.Marshal(data)
|
||||
if err != nil {
|
||||
log.Error().Err(err).Msg("cannot decode data when generating a JSON response")
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
w.WriteHeader(statusCode)
|
||||
w.Write(b)
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue