35 lines
527 B
Go
35 lines
527 B
Go
package server
|
|
|
|
import (
|
|
"net/http"
|
|
"time"
|
|
)
|
|
|
|
type Server struct {
|
|
Url string
|
|
}
|
|
|
|
func (s *Server) Start() error {
|
|
|
|
// Crear un servidor HTTP
|
|
server := http.Server{
|
|
Addr: s.Url,
|
|
ReadTimeout: 5 * time.Second, // time limit for reading
|
|
WriteTimeout: 5 * time.Second, // time limit for writting
|
|
IdleTimeout: 5 * time.Second,
|
|
}
|
|
// start api
|
|
go func() {
|
|
if err := server.ListenAndServe(); err != nil {
|
|
panic(err)
|
|
}
|
|
}()
|
|
return nil
|
|
}
|
|
|
|
func New(url string) *Server {
|
|
return &Server{
|
|
Url: url,
|
|
}
|
|
}
|