Skip to content

Instantly share code, notes, and snippets.

@quii
Created April 8, 2015 13:53
Show Gist options
  • Save quii/fd1b9f91fedad35796f9 to your computer and use it in GitHub Desktop.
Save quii/fd1b9f91fedad35796f9 to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
"net/http"
)
type CoPublisher struct {
id string
link string
name string
}
func main() {
databse := make(map[string]CoPublisher)
databse["foo"] = CoPublisher{"id", "htt:;///", "name"}
databse["bar"] = CoPublisher{"id", "htt:;///", "name"}
databse["baz"] = CoPublisher{"id", "htt:;///", "name"}
server := Server{databse}
http.Handle("/", server)
http.ListenAndServe(":8080", nil)
}
type Server struct {
Database map[string]CoPublisher
}
func (s Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
id := r.URL.Query().Get("id")
if val, ok := s.Database[id]; ok {
fmt.Fprintln(w, val)
} else {
http.Error(w, "Couldnt find copublisher", http.StatusNotFound)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment