Created
April 8, 2015 13:53
-
-
Save quii/fd1b9f91fedad35796f9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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