Skip to content

Instantly share code, notes, and snippets.

@oliverpauffley
Created April 20, 2019 09:27
Show Gist options
  • Save oliverpauffley/45f72dc04e63344677a060aa746da0b1 to your computer and use it in GitHub Desktop.
Save oliverpauffley/45f72dc04e63344677a060aa746da0b1 to your computer and use it in GitHub Desktop.
Handlers
package main
import (
"fmt"
"net/http"
)
type PlayerServer struct {
store PlayerStore
router *http.ServeMux
}
type PlayerStore interface {
GetPlayerScore(name string) int
RecordWin(name string)
}
func NewPlayerServer(store PlayerStore) *PlayerServer {
p := &PlayerServer{
store,
http.NewServeMux(),
}
p.router.Handle("/league", http.HandlerFunc(p.leagueHandler))
p.router.Handle("/players/", http.HandlerFunc(p.playersHandler))
return p
}
func (p *PlayerServer) ServeHTTP(w http.ResponseWriter, r *http.Request) {
p.router.ServeHTTP(w, r)
}
// I'm not really sure on the last line. Is p.router.ServeHTTP running to a different function than my ServeHTTP?
// Get Playerscore and Record win are defined but doesn't matter for my question.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment