This repository has been archived on 2022-11-30. You can view files and clone it, but cannot push or open issues or pull requests.
tacitus/http/server.go
2017-09-23 11:26:52 -07:00

44 lines
540 B
Go

package http
import (
"net"
"net/http"
)
const DefaultAddr = ":8080"
type Server struct {
Addr string
Handler *Mux
Err chan error
listener net.Listener
}
func NewServer() *Server {
return &Server{Addr: DefaultAddr,
Handler: NewMux()}
}
func (s *Server) Open() error {
ln, err := net.Listen("tcp", s.Addr)
if err != nil {
return err
}
s.listener = ln
go func() { http.Serve(s.listener, s.Handler) }()
return nil
}
func (s *Server) Close() error {
if s.listener != nil {
s.listener.Close()
}
return nil
}