Abdulmujeeb Raji
e08adc96ae
Introducing a unified signup and login API. You can post to the /user route with credentials (so far just name and password), and if the user doesn't exist, we create the user and return a token. If the user does exist, if the password inputted matches the database password, we return a token for that user, else we return an error. i've never wanted to kms more during a programming session
41 lines
649 B
Go
41 lines
649 B
Go
package main
|
|
|
|
import (
|
|
"log"
|
|
"net/http"
|
|
"os"
|
|
)
|
|
|
|
type App struct {
|
|
UserHandler *UserHandler
|
|
}
|
|
|
|
func (h *App) ServeHTTP(res http.ResponseWriter, req *http.Request) {
|
|
var head string
|
|
head, req.URL.Path = ShiftPath(req.URL.Path)
|
|
switch head {
|
|
case "user":
|
|
h.UserHandler.Handle(res, req)
|
|
default:
|
|
http.Error(res, "Not Found", http.StatusNotFound)
|
|
}
|
|
}
|
|
|
|
func main() {
|
|
user_handler, err := NewUserHandler()
|
|
if err != nil {
|
|
log.Fatalln(err)
|
|
}
|
|
|
|
a := &App{
|
|
UserHandler: user_handler,
|
|
}
|
|
|
|
port := os.Getenv("PORT")
|
|
if port == "" {
|
|
port = "7741"
|
|
}
|
|
log.Println("Ambition going strong at port 7741")
|
|
http.ListenAndServe(":"+port, a)
|
|
}
|