justlog/api/server.go

42 lines
884 B
Go
Raw Normal View History

2017-03-08 21:38:01 +01:00
package api
import (
2017-10-07 13:49:09 +02:00
"fmt"
2017-03-08 21:38:01 +01:00
"net/http"
2017-09-12 19:47:30 +02:00
"github.com/labstack/echo"
2017-03-08 21:38:01 +01:00
)
2017-09-12 19:47:30 +02:00
// Server api server
2017-03-08 21:38:01 +01:00
type Server struct {
2017-03-11 21:51:08 +01:00
port string
2017-03-08 21:38:01 +01:00
logPath string
}
2017-09-12 19:47:30 +02:00
// NewServer create Server
2017-09-13 21:12:11 +02:00
func NewServer() Server {
2017-03-08 21:38:01 +01:00
return Server{
2017-09-13 21:12:11 +02:00
logPath: "/var/twitch_logs",
2017-03-08 21:38:01 +01:00
}
}
2017-09-12 19:47:30 +02:00
// Init api server
2017-03-08 21:38:01 +01:00
func (s *Server) Init() {
e := echo.New()
2017-10-07 13:49:09 +02:00
e.HideBanner = true
2017-03-08 21:38:01 +01:00
e.GET("/", func(c echo.Context) error {
return c.String(http.StatusOK, "Hello, World!")
})
2017-03-11 11:33:50 +01:00
e.GET("/channel/:channel/user/:username", s.getCurrentUserLogs)
2018-03-02 20:18:12 +01:00
e.GET("/channel", s.getAllChannels)
2017-03-11 11:33:50 +01:00
e.GET("/channel/:channel", s.getCurrentChannelLogs)
e.GET("/channel/:channel/:year/:month/:day", s.getDatedChannelLogs)
2017-03-11 11:33:50 +01:00
e.GET("/channel/:channel/user/:username/:year/:month", s.getDatedUserLogs)
2017-03-08 21:38:01 +01:00
e.GET("/channel/:channel/user/:username/random", s.getRandomQuote)
2017-10-07 13:49:09 +02:00
fmt.Println("starting API on port :8025")
2017-09-13 21:12:11 +02:00
e.Logger.Fatal(e.Start(":8025"))
2017-03-11 21:51:08 +01:00
}