notes-server/server/routes.go

40 lines
699 B
Go
Executable File

package server
import (
"fmt"
"local/router"
"net/http"
)
func (s *Server) Routes() error {
wildcard := router.Wildcard
endpoints := []struct {
path string
handler http.HandlerFunc
}{
{
path: fmt.Sprintf("notes/%s%s", wildcard, wildcard),
handler: s.notes,
},
{
path: fmt.Sprintf("edit/%s%s", wildcard, wildcard),
handler: s.edit,
},
{
path: fmt.Sprintf("submit/%s%s", wildcard, wildcard),
handler: s.submit,
},
{
path: fmt.Sprintf("create/%s%s", wildcard, wildcard),
handler: s.create,
},
}
for _, endpoint := range endpoints {
if err := s.Add(endpoint.path, endpoint.handler); err != nil {
return err
}
}
return nil
}