use http.Method* instead of strings

This commit is contained in:
Adrien Marquès 2019-05-02 20:55:36 +02:00
parent cde7fa4798
commit aaa4fe9adf
2 changed files with 6 additions and 5 deletions

View File

@ -5,6 +5,7 @@ import (
"database/sql" "database/sql"
"encoding/hex" "encoding/hex"
"log" "log"
"net/http"
"strconv" "strconv"
"strings" "strings"
"time" "time"
@ -39,7 +40,7 @@ func New(storage *sql.DB) (*Service, error) {
// Wire to the aicra server // Wire to the aicra server
func (svc *Service) Wire(server *aicra.Server) { func (svc *Service) Wire(server *aicra.Server) {
log.Printf("[auth] service wired") log.Printf("[auth] service wired")
server.HandleFunc("POST", "/token", svc.generateToken) server.HandleFunc(http.MethodPost, "/token", svc.generateToken)
} }
// generateToken generates a token valid for 5 mintes // generateToken generates a token valid for 5 mintes

View File

@ -38,10 +38,10 @@ func New(storage *sql.DB, auth *auth.Service) (*Service, error) {
// Wire to the aicra server // Wire to the aicra server
func (svc *Service) Wire(server *aicra.Server) { func (svc *Service) Wire(server *aicra.Server) {
log.Printf("[shortener] service wired") log.Printf("[shortener] service wired")
server.HandleFunc("GET", "/", svc.redirect) server.HandleFunc(http.MethodGet, "/", svc.redirect)
server.HandleFunc("POST", "/", svc.authService.CheckToken(svc.register)) server.HandleFunc(http.MethodPost, "/", svc.authService.CheckToken(svc.register))
server.HandleFunc("PUT", "/", svc.authService.CheckToken(svc.update)) server.HandleFunc(http.MethodPut, "/", svc.authService.CheckToken(svc.update))
server.HandleFunc("DELETE", "/", svc.authService.CheckToken(svc.delete)) server.HandleFunc(http.MethodDelete, "/", svc.authService.CheckToken(svc.delete))
} }
// redirect from a tiny url to the long url // redirect from a tiny url to the long url