gobuch/microservices/jwt/server/main.go

32 lines
517 B
Go
Raw Permalink Normal View History

2020-08-21 04:26:40 +00:00
package main
import (
"log"
"net/http"
"golang.source-fellows.com/samples/jwt/server/jwt"
)
func handle(res http.ResponseWriter, req *http.Request) {
token, err := jwt.CreateToken()
if err != nil {
log.Fatal(err)
res.WriteHeader(http.StatusInternalServerError)
return
}
err = jwt.ValidateToken(token)
if err != nil {
log.Fatal(err)
res.WriteHeader(http.StatusInternalServerError)
return
}
res.Write(token)
}
func main() {
http.HandleFunc("/", handle)
http.ListenAndServe(":8080", nil)
}