Skip to content

Instantly share code, notes, and snippets.

@kellabyte
Created September 23, 2013 22:49
Show Gist options
  • Select an option

  • Save kellabyte/6678088 to your computer and use it in GitHub Desktop.

Select an option

Save kellabyte/6678088 to your computer and use it in GitHub Desktop.
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