Created
September 23, 2013 22:49
-
-
Save kellabyte/6678088 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 libdazzle | |
| import ( | |
| "fmt" | |
| "net/http" | |
| "strconv" | |
| "time" | |
| ) | |
| type HttpServer struct { | |
| address string | |
| port int | |
| listening bool | |
| db *Database | |
| } | |
| func NewHttpServer(db *Database) (*HttpServer, error) { | |
| server := &HttpServer{} | |
| server.db = db | |
| return server, nil | |
| } | |
| func (httpServer *HttpServer) Open(address string, port int) error { | |
| fmt.Printf("Listening on %s:%d\n", address, port) | |
| svr := &HTTP_SERVER{} | |
| server := &http.Server{ | |
| Addr: address + ":" + strconv.Itoa(port), | |
| Handler: svr, | |
| ReadTimeout: 10 * time.Second, | |
| WriteTimeout: 10 * time.Second, | |
| MaxHeaderBytes: 1 << 20, | |
| } | |
| server.ListenAndServe() | |
| return nil | |
| } | |
| type HTTP_SERVER struct { | |
| handler *http.Handler | |
| } | |
| func (server *HTTP_SERVER) ServeHTTP(response http.ResponseWriter, request *http.Request) { | |
| fmt.Fprintf(response, "hello world") | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment