Merge pull request #27 from gempir/docker
improving docs and changing makefile to build docker
This commit is contained in:
commit
f0bda87240
9 changed files with 907 additions and 32 deletions
|
@ -1,6 +1,5 @@
|
|||
language: go
|
||||
go:
|
||||
- 1.9.x
|
||||
- 1.10.x
|
||||
- 1.11.x
|
||||
- 1.12.x
|
||||
|
|
10
Makefile
10
Makefile
|
@ -5,13 +5,11 @@ build: get
|
|||
get:
|
||||
go get ./...
|
||||
|
||||
build_prod: get
|
||||
swag init
|
||||
env GOOS=linux GOARCH=arm go build
|
||||
container:
|
||||
docker build -t gempir/justlog .
|
||||
|
||||
deploy: build_prod
|
||||
rsync -avzhe ssh justlog root@apollo.gempir.com:/home/justlog/
|
||||
ssh root@apollo.gempir.com systemctl restart justlog.service
|
||||
release:
|
||||
docker push gempir/justlog
|
||||
|
||||
provision:
|
||||
ansible-playbook -i ansible/hosts ansible/playbook.yml --ask-vault-pass ${ARGS}
|
|
@ -44,7 +44,7 @@ func (s *Server) getChannelLogsByName(c echo.Context) error {
|
|||
userMap, err := s.helixClient.GetUsersByUsernames([]string{channel})
|
||||
if err != nil {
|
||||
log.Error(err)
|
||||
return c.JSON(http.StatusInternalServerError, "Failure fetching userID")
|
||||
return c.JSON(http.StatusInternalServerError, "Failure fetching data from twitch")
|
||||
}
|
||||
|
||||
names := c.ParamNames()
|
||||
|
@ -65,7 +65,7 @@ func (s *Server) getChannelLogsRangeByName(c echo.Context) error {
|
|||
userMap, err := s.helixClient.GetUsersByUsernames([]string{channel})
|
||||
if err != nil {
|
||||
log.Error(err)
|
||||
return c.JSON(http.StatusInternalServerError, "Failure fetching userID")
|
||||
return c.JSON(http.StatusInternalServerError, "Failure fetching data from twitch")
|
||||
}
|
||||
|
||||
names := c.ParamNames()
|
||||
|
|
|
@ -10,6 +10,7 @@ import (
|
|||
"time"
|
||||
|
||||
"github.com/gempir/justlog/helix"
|
||||
log "github.com/sirupsen/logrus"
|
||||
|
||||
twitch "github.com/gempir/go-twitch-irc"
|
||||
"github.com/gempir/justlog/filelog"
|
||||
|
@ -29,13 +30,13 @@ type Server struct {
|
|||
channels []string
|
||||
}
|
||||
|
||||
func NewServer(logPath string, listenAddress string, fileLogger *filelog.Logger, helixClient *helix.Client) Server {
|
||||
func NewServer(logPath string, listenAddress string, fileLogger *filelog.Logger, helixClient *helix.Client, channels []string) Server {
|
||||
return Server{
|
||||
listenAddress: listenAddress,
|
||||
logPath: logPath,
|
||||
fileLogger: fileLogger,
|
||||
helixClient: helixClient,
|
||||
channels: []string{},
|
||||
channels: channels,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -69,7 +70,7 @@ func (s *Server) Init() {
|
|||
return c.Redirect(http.StatusMovedPermanently, "/index.html")
|
||||
})
|
||||
e.GET("/*", echoSwagger.WrapHandler)
|
||||
e.GET("/channelid", s.getAllChannels)
|
||||
e.GET("/channels", s.getAllChannels)
|
||||
|
||||
e.GET("/channel/:channel/user/:username/range", s.getUserLogsRangeByName)
|
||||
e.GET("/channelid/:channelid/userid/:userid/range", s.getUserLogsRange)
|
||||
|
@ -98,8 +99,13 @@ var (
|
|||
channelHourLimit = 24.0
|
||||
)
|
||||
|
||||
type channel struct {
|
||||
UserID string `json:"userID"`
|
||||
Name string `json:"name"`
|
||||
}
|
||||
|
||||
type AllChannelsJSON struct {
|
||||
Channels []string `json:"channels"`
|
||||
Channels []channel `json:"channels"`
|
||||
}
|
||||
|
||||
type chatLog struct {
|
||||
|
@ -115,7 +121,7 @@ type chatMessage struct {
|
|||
Type twitch.MessageType `json:"type"`
|
||||
}
|
||||
|
||||
type errorResponse struct {
|
||||
type ErrorResponse struct {
|
||||
Message string `json:"message"`
|
||||
}
|
||||
|
||||
|
@ -130,9 +136,26 @@ func reverse(input []string) []string {
|
|||
return input
|
||||
}
|
||||
|
||||
// getAllChannels godoc
|
||||
// @Summary Get all joined channels
|
||||
// @tags bot
|
||||
// @Produce json
|
||||
// @Success 200 {object} api.RandomQuoteJSON json
|
||||
// @Failure 500 {object} api.ErrorResponse json
|
||||
// @Router /channels [get]
|
||||
func (s *Server) getAllChannels(c echo.Context) error {
|
||||
response := new(AllChannelsJSON)
|
||||
response.Channels = s.channels
|
||||
response.Channels = []channel{}
|
||||
users, err := s.helixClient.GetUsersByUserIds(s.channels)
|
||||
|
||||
if err != nil {
|
||||
log.Error(err)
|
||||
return c.JSON(http.StatusInternalServerError, ErrorResponse{"Failure fetching data from twitch"})
|
||||
}
|
||||
|
||||
for _, user := range users {
|
||||
response.Channels = append(response.Channels, channel{UserID: user.ID, Name: user.Login})
|
||||
}
|
||||
|
||||
return c.JSON(http.StatusOK, response)
|
||||
}
|
||||
|
|
83
api/user.go
83
api/user.go
|
@ -19,13 +19,27 @@ type RandomQuoteJSON struct {
|
|||
Timestamp timestamp `json:"timestamp"`
|
||||
}
|
||||
|
||||
// @Summary Redirect to last logs of user
|
||||
// @tags user
|
||||
// @Produce json
|
||||
// @Produce plain
|
||||
// @Param channelid path string true "twitch userid"
|
||||
// @Param userid path string true "twitch userid"
|
||||
// @Param from query int false "unix timestamp, limit logs by timestamps from this point"
|
||||
// @Param to query int false "unix timestamp, limit logs by timestamps to this point"
|
||||
// @Param json query any false "response as json"
|
||||
// @Param type query string false "define response type only json supported currently, rest defaults to plain"
|
||||
// @Success 303
|
||||
// @Success 200
|
||||
// @Failure 404
|
||||
// @Router /channelid/{channelid}/user/{userid} [get]
|
||||
func (s *Server) getLastUserLogs(c echo.Context) error {
|
||||
channelID := c.Param("channelid")
|
||||
userID := c.Param("userid")
|
||||
|
||||
year, month, err := s.fileLogger.GetLastLogYearAndMonthForUser(channelID, userID)
|
||||
if err != nil {
|
||||
return c.JSON(http.StatusNotFound, errorResponse{"No logs found"})
|
||||
return c.JSON(http.StatusNotFound, ErrorResponse{"No logs found"})
|
||||
}
|
||||
|
||||
redirectURL := fmt.Sprintf("/channelid/%s/userid/%s/%d/%d", channelID, userID, year, month)
|
||||
|
@ -35,16 +49,20 @@ func (s *Server) getLastUserLogs(c echo.Context) error {
|
|||
return c.Redirect(303, redirectURL)
|
||||
}
|
||||
|
||||
// getLastUserLogsByName godoc
|
||||
// @Summary Redirect to last logs of user
|
||||
// @tags user
|
||||
// @Produce json
|
||||
// @Produce plain
|
||||
// @Param channel path string true "channelname"
|
||||
// @Param username path string true "username"
|
||||
// @Param from query int false "unix timestamp, limit logs by timestamps from this point"
|
||||
// @Param to query int false "unix timestamp, limit logs by timestamps to this point"
|
||||
// @Param json query any false "response as json"
|
||||
// @Param type query string false "define response type only json supported currently, rest defaults to plain"
|
||||
// @Success 303
|
||||
// @Success 200
|
||||
// @Failure 500
|
||||
// @Failure 404
|
||||
// @Router /channel/{channel}/user/{username} [get]
|
||||
func (s *Server) getLastUserLogsByName(c echo.Context) error {
|
||||
channel := strings.ToLower(c.Param("channel"))
|
||||
|
@ -53,13 +71,13 @@ func (s *Server) getLastUserLogsByName(c echo.Context) error {
|
|||
userMap, err := s.helixClient.GetUsersByUsernames([]string{channel, username})
|
||||
if err != nil {
|
||||
log.Error(err)
|
||||
return c.JSON(http.StatusInternalServerError, errorResponse{"Failure fetching userIDs"})
|
||||
return c.JSON(http.StatusInternalServerError, ErrorResponse{"Failure fetching data from twitch"})
|
||||
}
|
||||
var year int
|
||||
var month int
|
||||
year, month, err = s.fileLogger.GetLastLogYearAndMonthForUser(userMap[channel].ID, userMap[username].ID)
|
||||
if err != nil {
|
||||
return c.JSON(http.StatusNotFound, errorResponse{"No logs found"})
|
||||
return c.JSON(http.StatusNotFound, ErrorResponse{"No logs found"})
|
||||
}
|
||||
|
||||
redirectURL := fmt.Sprintf("/channel/%s/user/%s/%d/%d", channel, username, year, month)
|
||||
|
@ -76,7 +94,7 @@ func (s *Server) getUserLogsRangeByName(c echo.Context) error {
|
|||
userMap, err := s.helixClient.GetUsersByUsernames([]string{channel, username})
|
||||
if err != nil {
|
||||
log.Error(err)
|
||||
return c.JSON(http.StatusInternalServerError, errorResponse{"Failure fetching userIDs"})
|
||||
return c.JSON(http.StatusInternalServerError, ErrorResponse{"Failure fetching data from twitch"})
|
||||
}
|
||||
|
||||
names := c.ParamNames()
|
||||
|
@ -93,6 +111,21 @@ func (s *Server) getUserLogsRangeByName(c echo.Context) error {
|
|||
return s.getUserLogsRange(c)
|
||||
}
|
||||
|
||||
// @Summary Get logs for user by year and month
|
||||
// @tags user
|
||||
// @Produce json
|
||||
// @Produce plain
|
||||
// @Param channel path string true "channelname"
|
||||
// @Param username path string true "username"
|
||||
// @Param year path string true "year of logs"
|
||||
// @Param month path string true "month of logs"
|
||||
// @Param from query int false "unix timestamp, limit logs by timestamps from this point"
|
||||
// @Param to query int false "unix timestamp, limit logs by timestamps to this point"
|
||||
// @Param json query any false "response as json"
|
||||
// @Param type query string false "define response type only json supported currently, rest defaults to plain"
|
||||
// @Success 200
|
||||
// @Failure 500
|
||||
// @Router /channel/{channel}/user/{username}/{year}/{month} [get]
|
||||
func (s *Server) getUserLogsByName(c echo.Context) error {
|
||||
channel := strings.ToLower(c.Param("channel"))
|
||||
username := strings.ToLower(c.Param("username"))
|
||||
|
@ -100,7 +133,7 @@ func (s *Server) getUserLogsByName(c echo.Context) error {
|
|||
userMap, err := s.helixClient.GetUsersByUsernames([]string{channel, username})
|
||||
if err != nil {
|
||||
log.Error(err)
|
||||
return c.JSON(http.StatusInternalServerError, errorResponse{"Failure fetching userIDs"})
|
||||
return c.JSON(http.StatusInternalServerError, ErrorResponse{"Failure fetching data from twitch"})
|
||||
}
|
||||
|
||||
names := c.ParamNames()
|
||||
|
@ -117,7 +150,6 @@ func (s *Server) getUserLogsByName(c echo.Context) error {
|
|||
return s.getUserLogs(c)
|
||||
}
|
||||
|
||||
// getRandomQuoteByName godoc
|
||||
// @Summary Get a random chat message from a user
|
||||
// @tags user
|
||||
// @Produce json
|
||||
|
@ -135,7 +167,7 @@ func (s *Server) getRandomQuoteByName(c echo.Context) error {
|
|||
userMap, err := s.helixClient.GetUsersByUsernames([]string{channel, username})
|
||||
if err != nil {
|
||||
log.Error(err)
|
||||
return c.JSON(http.StatusInternalServerError, errorResponse{"Failure fetching userIDs"})
|
||||
return c.JSON(http.StatusInternalServerError, ErrorResponse{"Failure fetching data from twitch"})
|
||||
}
|
||||
|
||||
names := c.ParamNames()
|
||||
|
@ -152,6 +184,16 @@ func (s *Server) getRandomQuoteByName(c echo.Context) error {
|
|||
return s.getRandomQuote(c)
|
||||
}
|
||||
|
||||
// @Summary Get a random chat message from a user
|
||||
// @tags user
|
||||
// @Produce json
|
||||
// @Produce plain
|
||||
// @Param channelid path string true "twitch userid"
|
||||
// @Param userid path string true "twitch userid"
|
||||
// @Param json query any false "response as json"
|
||||
// @Param type query string false "define response type only json supported currently, rest defaults to plain"
|
||||
// @Success 200 {object} api.RandomQuoteJSON json
|
||||
// @Router /channelid/{channelid}/userid/{userid}/random [get]
|
||||
func (s *Server) getRandomQuote(c echo.Context) error {
|
||||
channelID := c.Param("channelid")
|
||||
userID := c.Param("userid")
|
||||
|
@ -202,6 +244,21 @@ func (s *Server) getRandomQuote(c echo.Context) error {
|
|||
return c.String(http.StatusNotFound, "No quote found")
|
||||
}
|
||||
|
||||
// @Summary Get logs for user by year and month
|
||||
// @tags user
|
||||
// @Produce json
|
||||
// @Produce plain
|
||||
// @Param channelid path string true "twitch userid"
|
||||
// @Param userid path string true "twitch userid"
|
||||
// @Param year path string true "year of logs"
|
||||
// @Param month path string true "month of logs"
|
||||
// @Param from query int false "unix timestamp, limit logs by timestamps from this point"
|
||||
// @Param to query int false "unix timestamp, limit logs by timestamps to this point"
|
||||
// @Param json query any false "response as json"
|
||||
// @Param type query string false "define response type only json supported currently, rest defaults to plain"
|
||||
// @Success 200
|
||||
// @Failure 500
|
||||
// @Router /channelid/{channelid}/userid/{userid}/{year}/{month} [get]
|
||||
func (s *Server) getUserLogs(c echo.Context) error {
|
||||
channelID := c.Param("channelid")
|
||||
userID := c.Param("userid")
|
||||
|
@ -212,18 +269,18 @@ func (s *Server) getUserLogs(c echo.Context) error {
|
|||
year, err := strconv.Atoi(yearStr)
|
||||
if err != nil {
|
||||
log.Error(err)
|
||||
return c.JSON(http.StatusInternalServerError, errorResponse{"Invalid year"})
|
||||
return c.JSON(http.StatusInternalServerError, ErrorResponse{"Invalid year"})
|
||||
}
|
||||
month, err := strconv.Atoi(monthStr)
|
||||
if err != nil {
|
||||
log.Error(err)
|
||||
return c.JSON(http.StatusInternalServerError, errorResponse{"Invalid month"})
|
||||
return c.JSON(http.StatusInternalServerError, ErrorResponse{"Invalid month"})
|
||||
}
|
||||
|
||||
logMessages, err := s.fileLogger.ReadLogForUser(channelID, userID, year, month)
|
||||
if err != nil {
|
||||
log.Error(err)
|
||||
return c.JSON(http.StatusInternalServerError, errorResponse{"Failure reading log"})
|
||||
return c.JSON(http.StatusInternalServerError, ErrorResponse{"Failure reading log"})
|
||||
}
|
||||
|
||||
if shouldReverse(c) {
|
||||
|
@ -285,7 +342,7 @@ func (s *Server) getUserLogsRange(c echo.Context) error {
|
|||
|
||||
fromTime, toTime, err := parseFromTo(c.QueryParam("from"), c.QueryParam("to"), userHourLimit)
|
||||
if err != nil {
|
||||
return c.JSON(http.StatusInternalServerError, errorResponse{err.Error()})
|
||||
return c.JSON(http.StatusInternalServerError, ErrorResponse{err.Error()})
|
||||
}
|
||||
|
||||
var logMessages []string
|
||||
|
@ -299,7 +356,7 @@ func (s *Server) getUserLogsRange(c echo.Context) error {
|
|||
}
|
||||
|
||||
if len(logMessages) == 0 {
|
||||
return c.JSON(http.StatusNotFound, errorResponse{"No logs found"})
|
||||
return c.JSON(http.StatusNotFound, ErrorResponse{"No logs found"})
|
||||
}
|
||||
|
||||
if shouldReverse(c) {
|
||||
|
|
300
docs/docs.go
300
docs/docs.go
|
@ -1,6 +1,6 @@
|
|||
// GENERATED BY THE COMMAND ABOVE; DO NOT EDIT
|
||||
// This file was generated by swaggo/swag at
|
||||
// 2019-04-30 20:13:45.728084 +0200 CEST m=+0.187900693
|
||||
// 2019-07-13 13:12:22.002809 +0200 CEST m=+0.187567695
|
||||
|
||||
package docs
|
||||
|
||||
|
@ -55,6 +55,18 @@ var doc = `{
|
|||
"in": "path",
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"type": "integer",
|
||||
"description": "unix timestamp, limit logs by timestamps from this point",
|
||||
"name": "from",
|
||||
"in": "query"
|
||||
},
|
||||
{
|
||||
"type": "integer",
|
||||
"description": "unix timestamp, limit logs by timestamps to this point",
|
||||
"name": "to",
|
||||
"in": "query"
|
||||
},
|
||||
{
|
||||
"type": "any",
|
||||
"description": "response as json",
|
||||
|
@ -69,7 +81,10 @@ var doc = `{
|
|||
}
|
||||
],
|
||||
"responses": {
|
||||
"303": {}
|
||||
"200": {},
|
||||
"303": {},
|
||||
"404": {},
|
||||
"500": {}
|
||||
}
|
||||
}
|
||||
},
|
||||
|
@ -121,9 +136,290 @@ var doc = `{
|
|||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/channel/{channel}/user/{username}/{year}/{month}": {
|
||||
"get": {
|
||||
"produces": [
|
||||
"application/json",
|
||||
"text/plain"
|
||||
],
|
||||
"tags": [
|
||||
"user"
|
||||
],
|
||||
"summary": "Get logs for user by year and month",
|
||||
"parameters": [
|
||||
{
|
||||
"type": "string",
|
||||
"description": "channelname",
|
||||
"name": "channel",
|
||||
"in": "path",
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"type": "string",
|
||||
"description": "username",
|
||||
"name": "username",
|
||||
"in": "path",
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"type": "string",
|
||||
"description": "year of logs",
|
||||
"name": "year",
|
||||
"in": "path",
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"type": "string",
|
||||
"description": "month of logs",
|
||||
"name": "month",
|
||||
"in": "path",
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"type": "integer",
|
||||
"description": "unix timestamp, limit logs by timestamps from this point",
|
||||
"name": "from",
|
||||
"in": "query"
|
||||
},
|
||||
{
|
||||
"type": "integer",
|
||||
"description": "unix timestamp, limit logs by timestamps to this point",
|
||||
"name": "to",
|
||||
"in": "query"
|
||||
},
|
||||
{
|
||||
"type": "any",
|
||||
"description": "response as json",
|
||||
"name": "json",
|
||||
"in": "query"
|
||||
},
|
||||
{
|
||||
"type": "string",
|
||||
"description": "define response type only json supported currently, rest defaults to plain",
|
||||
"name": "type",
|
||||
"in": "query"
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {},
|
||||
"500": {}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/channelid/{channelid}/user/{userid}": {
|
||||
"get": {
|
||||
"produces": [
|
||||
"application/json",
|
||||
"text/plain"
|
||||
],
|
||||
"tags": [
|
||||
"user"
|
||||
],
|
||||
"summary": "Redirect to last logs of user",
|
||||
"parameters": [
|
||||
{
|
||||
"type": "string",
|
||||
"description": "twitch userid",
|
||||
"name": "channelid",
|
||||
"in": "path",
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"type": "string",
|
||||
"description": "twitch userid",
|
||||
"name": "userid",
|
||||
"in": "path",
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"type": "integer",
|
||||
"description": "unix timestamp, limit logs by timestamps from this point",
|
||||
"name": "from",
|
||||
"in": "query"
|
||||
},
|
||||
{
|
||||
"type": "integer",
|
||||
"description": "unix timestamp, limit logs by timestamps to this point",
|
||||
"name": "to",
|
||||
"in": "query"
|
||||
},
|
||||
{
|
||||
"type": "any",
|
||||
"description": "response as json",
|
||||
"name": "json",
|
||||
"in": "query"
|
||||
},
|
||||
{
|
||||
"type": "string",
|
||||
"description": "define response type only json supported currently, rest defaults to plain",
|
||||
"name": "type",
|
||||
"in": "query"
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {},
|
||||
"303": {},
|
||||
"404": {}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/channelid/{channelid}/userid/{userid}/random": {
|
||||
"get": {
|
||||
"produces": [
|
||||
"application/json",
|
||||
"text/plain"
|
||||
],
|
||||
"tags": [
|
||||
"user"
|
||||
],
|
||||
"summary": "Get a random chat message from a user",
|
||||
"parameters": [
|
||||
{
|
||||
"type": "string",
|
||||
"description": "twitch userid",
|
||||
"name": "channelid",
|
||||
"in": "path",
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"type": "string",
|
||||
"description": "twitch userid",
|
||||
"name": "userid",
|
||||
"in": "path",
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"type": "any",
|
||||
"description": "response as json",
|
||||
"name": "json",
|
||||
"in": "query"
|
||||
},
|
||||
{
|
||||
"type": "string",
|
||||
"description": "define response type only json supported currently, rest defaults to plain",
|
||||
"name": "type",
|
||||
"in": "query"
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "OK",
|
||||
"schema": {
|
||||
"type": "object",
|
||||
"$ref": "#/definitions/api.RandomQuoteJSON"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/channelid/{channelid}/userid/{userid}/{year}/{month}": {
|
||||
"get": {
|
||||
"produces": [
|
||||
"application/json",
|
||||
"text/plain"
|
||||
],
|
||||
"tags": [
|
||||
"user"
|
||||
],
|
||||
"summary": "Get logs for user by year and month",
|
||||
"parameters": [
|
||||
{
|
||||
"type": "string",
|
||||
"description": "twitch userid",
|
||||
"name": "channelid",
|
||||
"in": "path",
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"type": "string",
|
||||
"description": "twitch userid",
|
||||
"name": "userid",
|
||||
"in": "path",
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"type": "string",
|
||||
"description": "year of logs",
|
||||
"name": "year",
|
||||
"in": "path",
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"type": "string",
|
||||
"description": "month of logs",
|
||||
"name": "month",
|
||||
"in": "path",
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"type": "integer",
|
||||
"description": "unix timestamp, limit logs by timestamps from this point",
|
||||
"name": "from",
|
||||
"in": "query"
|
||||
},
|
||||
{
|
||||
"type": "integer",
|
||||
"description": "unix timestamp, limit logs by timestamps to this point",
|
||||
"name": "to",
|
||||
"in": "query"
|
||||
},
|
||||
{
|
||||
"type": "any",
|
||||
"description": "response as json",
|
||||
"name": "json",
|
||||
"in": "query"
|
||||
},
|
||||
{
|
||||
"type": "string",
|
||||
"description": "define response type only json supported currently, rest defaults to plain",
|
||||
"name": "type",
|
||||
"in": "query"
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {},
|
||||
"500": {}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/channels": {
|
||||
"get": {
|
||||
"produces": [
|
||||
"application/json"
|
||||
],
|
||||
"tags": [
|
||||
"bot"
|
||||
],
|
||||
"summary": "Get all joined channels",
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "OK",
|
||||
"schema": {
|
||||
"type": "object",
|
||||
"$ref": "#/definitions/api.RandomQuoteJSON"
|
||||
}
|
||||
},
|
||||
"500": {
|
||||
"description": "Internal Server Error",
|
||||
"schema": {
|
||||
"type": "object",
|
||||
"$ref": "#/definitions/api.ErrorResponse"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"definitions": {
|
||||
"api.ErrorResponse": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"message": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
},
|
||||
"api.RandomQuoteJSON": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
|
|
|
@ -42,6 +42,18 @@
|
|||
"in": "path",
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"type": "integer",
|
||||
"description": "unix timestamp, limit logs by timestamps from this point",
|
||||
"name": "from",
|
||||
"in": "query"
|
||||
},
|
||||
{
|
||||
"type": "integer",
|
||||
"description": "unix timestamp, limit logs by timestamps to this point",
|
||||
"name": "to",
|
||||
"in": "query"
|
||||
},
|
||||
{
|
||||
"type": "any",
|
||||
"description": "response as json",
|
||||
|
@ -56,7 +68,10 @@
|
|||
}
|
||||
],
|
||||
"responses": {
|
||||
"303": {}
|
||||
"200": {},
|
||||
"303": {},
|
||||
"404": {},
|
||||
"500": {}
|
||||
}
|
||||
}
|
||||
},
|
||||
|
@ -108,9 +123,290 @@
|
|||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/channel/{channel}/user/{username}/{year}/{month}": {
|
||||
"get": {
|
||||
"produces": [
|
||||
"application/json",
|
||||
"text/plain"
|
||||
],
|
||||
"tags": [
|
||||
"user"
|
||||
],
|
||||
"summary": "Get logs for user by year and month",
|
||||
"parameters": [
|
||||
{
|
||||
"type": "string",
|
||||
"description": "channelname",
|
||||
"name": "channel",
|
||||
"in": "path",
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"type": "string",
|
||||
"description": "username",
|
||||
"name": "username",
|
||||
"in": "path",
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"type": "string",
|
||||
"description": "year of logs",
|
||||
"name": "year",
|
||||
"in": "path",
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"type": "string",
|
||||
"description": "month of logs",
|
||||
"name": "month",
|
||||
"in": "path",
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"type": "integer",
|
||||
"description": "unix timestamp, limit logs by timestamps from this point",
|
||||
"name": "from",
|
||||
"in": "query"
|
||||
},
|
||||
{
|
||||
"type": "integer",
|
||||
"description": "unix timestamp, limit logs by timestamps to this point",
|
||||
"name": "to",
|
||||
"in": "query"
|
||||
},
|
||||
{
|
||||
"type": "any",
|
||||
"description": "response as json",
|
||||
"name": "json",
|
||||
"in": "query"
|
||||
},
|
||||
{
|
||||
"type": "string",
|
||||
"description": "define response type only json supported currently, rest defaults to plain",
|
||||
"name": "type",
|
||||
"in": "query"
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {},
|
||||
"500": {}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/channelid/{channelid}/user/{userid}": {
|
||||
"get": {
|
||||
"produces": [
|
||||
"application/json",
|
||||
"text/plain"
|
||||
],
|
||||
"tags": [
|
||||
"user"
|
||||
],
|
||||
"summary": "Redirect to last logs of user",
|
||||
"parameters": [
|
||||
{
|
||||
"type": "string",
|
||||
"description": "twitch userid",
|
||||
"name": "channelid",
|
||||
"in": "path",
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"type": "string",
|
||||
"description": "twitch userid",
|
||||
"name": "userid",
|
||||
"in": "path",
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"type": "integer",
|
||||
"description": "unix timestamp, limit logs by timestamps from this point",
|
||||
"name": "from",
|
||||
"in": "query"
|
||||
},
|
||||
{
|
||||
"type": "integer",
|
||||
"description": "unix timestamp, limit logs by timestamps to this point",
|
||||
"name": "to",
|
||||
"in": "query"
|
||||
},
|
||||
{
|
||||
"type": "any",
|
||||
"description": "response as json",
|
||||
"name": "json",
|
||||
"in": "query"
|
||||
},
|
||||
{
|
||||
"type": "string",
|
||||
"description": "define response type only json supported currently, rest defaults to plain",
|
||||
"name": "type",
|
||||
"in": "query"
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {},
|
||||
"303": {},
|
||||
"404": {}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/channelid/{channelid}/userid/{userid}/random": {
|
||||
"get": {
|
||||
"produces": [
|
||||
"application/json",
|
||||
"text/plain"
|
||||
],
|
||||
"tags": [
|
||||
"user"
|
||||
],
|
||||
"summary": "Get a random chat message from a user",
|
||||
"parameters": [
|
||||
{
|
||||
"type": "string",
|
||||
"description": "twitch userid",
|
||||
"name": "channelid",
|
||||
"in": "path",
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"type": "string",
|
||||
"description": "twitch userid",
|
||||
"name": "userid",
|
||||
"in": "path",
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"type": "any",
|
||||
"description": "response as json",
|
||||
"name": "json",
|
||||
"in": "query"
|
||||
},
|
||||
{
|
||||
"type": "string",
|
||||
"description": "define response type only json supported currently, rest defaults to plain",
|
||||
"name": "type",
|
||||
"in": "query"
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "OK",
|
||||
"schema": {
|
||||
"type": "object",
|
||||
"$ref": "#/definitions/api.RandomQuoteJSON"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/channelid/{channelid}/userid/{userid}/{year}/{month}": {
|
||||
"get": {
|
||||
"produces": [
|
||||
"application/json",
|
||||
"text/plain"
|
||||
],
|
||||
"tags": [
|
||||
"user"
|
||||
],
|
||||
"summary": "Get logs for user by year and month",
|
||||
"parameters": [
|
||||
{
|
||||
"type": "string",
|
||||
"description": "twitch userid",
|
||||
"name": "channelid",
|
||||
"in": "path",
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"type": "string",
|
||||
"description": "twitch userid",
|
||||
"name": "userid",
|
||||
"in": "path",
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"type": "string",
|
||||
"description": "year of logs",
|
||||
"name": "year",
|
||||
"in": "path",
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"type": "string",
|
||||
"description": "month of logs",
|
||||
"name": "month",
|
||||
"in": "path",
|
||||
"required": true
|
||||
},
|
||||
{
|
||||
"type": "integer",
|
||||
"description": "unix timestamp, limit logs by timestamps from this point",
|
||||
"name": "from",
|
||||
"in": "query"
|
||||
},
|
||||
{
|
||||
"type": "integer",
|
||||
"description": "unix timestamp, limit logs by timestamps to this point",
|
||||
"name": "to",
|
||||
"in": "query"
|
||||
},
|
||||
{
|
||||
"type": "any",
|
||||
"description": "response as json",
|
||||
"name": "json",
|
||||
"in": "query"
|
||||
},
|
||||
{
|
||||
"type": "string",
|
||||
"description": "define response type only json supported currently, rest defaults to plain",
|
||||
"name": "type",
|
||||
"in": "query"
|
||||
}
|
||||
],
|
||||
"responses": {
|
||||
"200": {},
|
||||
"500": {}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/channels": {
|
||||
"get": {
|
||||
"produces": [
|
||||
"application/json"
|
||||
],
|
||||
"tags": [
|
||||
"bot"
|
||||
],
|
||||
"summary": "Get all joined channels",
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "OK",
|
||||
"schema": {
|
||||
"type": "object",
|
||||
"$ref": "#/definitions/api.RandomQuoteJSON"
|
||||
}
|
||||
},
|
||||
"500": {
|
||||
"description": "Internal Server Error",
|
||||
"schema": {
|
||||
"type": "object",
|
||||
"$ref": "#/definitions/api.ErrorResponse"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"definitions": {
|
||||
"api.ErrorResponse": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"message": {
|
||||
"type": "string"
|
||||
}
|
||||
}
|
||||
},
|
||||
"api.RandomQuoteJSON": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
|
|
|
@ -1,5 +1,10 @@
|
|||
basePath: /
|
||||
definitions:
|
||||
api.ErrorResponse:
|
||||
properties:
|
||||
message:
|
||||
type: string
|
||||
type: object
|
||||
api.RandomQuoteJSON:
|
||||
properties:
|
||||
channel:
|
||||
|
@ -42,6 +47,14 @@ paths:
|
|||
name: username
|
||||
required: true
|
||||
type: string
|
||||
- description: unix timestamp, limit logs by timestamps from this point
|
||||
in: query
|
||||
name: from
|
||||
type: integer
|
||||
- description: unix timestamp, limit logs by timestamps to this point
|
||||
in: query
|
||||
name: to
|
||||
type: integer
|
||||
- description: response as json
|
||||
in: query
|
||||
name: json
|
||||
|
@ -55,10 +68,62 @@ paths:
|
|||
- application/json
|
||||
- text/plain
|
||||
responses:
|
||||
"200": {}
|
||||
"303": {}
|
||||
"404": {}
|
||||
"500": {}
|
||||
summary: Redirect to last logs of user
|
||||
tags:
|
||||
- user
|
||||
/channel/{channel}/user/{username}/{year}/{month}:
|
||||
get:
|
||||
parameters:
|
||||
- description: channelname
|
||||
in: path
|
||||
name: channel
|
||||
required: true
|
||||
type: string
|
||||
- description: username
|
||||
in: path
|
||||
name: username
|
||||
required: true
|
||||
type: string
|
||||
- description: year of logs
|
||||
in: path
|
||||
name: year
|
||||
required: true
|
||||
type: string
|
||||
- description: month of logs
|
||||
in: path
|
||||
name: month
|
||||
required: true
|
||||
type: string
|
||||
- description: unix timestamp, limit logs by timestamps from this point
|
||||
in: query
|
||||
name: from
|
||||
type: integer
|
||||
- description: unix timestamp, limit logs by timestamps to this point
|
||||
in: query
|
||||
name: to
|
||||
type: integer
|
||||
- description: response as json
|
||||
in: query
|
||||
name: json
|
||||
type: any
|
||||
- description: define response type only json supported currently, rest defaults
|
||||
to plain
|
||||
in: query
|
||||
name: type
|
||||
type: string
|
||||
produces:
|
||||
- application/json
|
||||
- text/plain
|
||||
responses:
|
||||
"200": {}
|
||||
"500": {}
|
||||
summary: Get logs for user by year and month
|
||||
tags:
|
||||
- user
|
||||
/channel/{channel}/user/{username}/random:
|
||||
get:
|
||||
parameters:
|
||||
|
@ -93,4 +158,145 @@ paths:
|
|||
summary: Get a random chat message from a user
|
||||
tags:
|
||||
- user
|
||||
/channelid/{channelid}/user/{userid}:
|
||||
get:
|
||||
parameters:
|
||||
- description: twitch userid
|
||||
in: path
|
||||
name: channelid
|
||||
required: true
|
||||
type: string
|
||||
- description: twitch userid
|
||||
in: path
|
||||
name: userid
|
||||
required: true
|
||||
type: string
|
||||
- description: unix timestamp, limit logs by timestamps from this point
|
||||
in: query
|
||||
name: from
|
||||
type: integer
|
||||
- description: unix timestamp, limit logs by timestamps to this point
|
||||
in: query
|
||||
name: to
|
||||
type: integer
|
||||
- description: response as json
|
||||
in: query
|
||||
name: json
|
||||
type: any
|
||||
- description: define response type only json supported currently, rest defaults
|
||||
to plain
|
||||
in: query
|
||||
name: type
|
||||
type: string
|
||||
produces:
|
||||
- application/json
|
||||
- text/plain
|
||||
responses:
|
||||
"200": {}
|
||||
"303": {}
|
||||
"404": {}
|
||||
summary: Redirect to last logs of user
|
||||
tags:
|
||||
- user
|
||||
/channelid/{channelid}/userid/{userid}/{year}/{month}:
|
||||
get:
|
||||
parameters:
|
||||
- description: twitch userid
|
||||
in: path
|
||||
name: channelid
|
||||
required: true
|
||||
type: string
|
||||
- description: twitch userid
|
||||
in: path
|
||||
name: userid
|
||||
required: true
|
||||
type: string
|
||||
- description: year of logs
|
||||
in: path
|
||||
name: year
|
||||
required: true
|
||||
type: string
|
||||
- description: month of logs
|
||||
in: path
|
||||
name: month
|
||||
required: true
|
||||
type: string
|
||||
- description: unix timestamp, limit logs by timestamps from this point
|
||||
in: query
|
||||
name: from
|
||||
type: integer
|
||||
- description: unix timestamp, limit logs by timestamps to this point
|
||||
in: query
|
||||
name: to
|
||||
type: integer
|
||||
- description: response as json
|
||||
in: query
|
||||
name: json
|
||||
type: any
|
||||
- description: define response type only json supported currently, rest defaults
|
||||
to plain
|
||||
in: query
|
||||
name: type
|
||||
type: string
|
||||
produces:
|
||||
- application/json
|
||||
- text/plain
|
||||
responses:
|
||||
"200": {}
|
||||
"500": {}
|
||||
summary: Get logs for user by year and month
|
||||
tags:
|
||||
- user
|
||||
/channelid/{channelid}/userid/{userid}/random:
|
||||
get:
|
||||
parameters:
|
||||
- description: twitch userid
|
||||
in: path
|
||||
name: channelid
|
||||
required: true
|
||||
type: string
|
||||
- description: twitch userid
|
||||
in: path
|
||||
name: userid
|
||||
required: true
|
||||
type: string
|
||||
- description: response as json
|
||||
in: query
|
||||
name: json
|
||||
type: any
|
||||
- description: define response type only json supported currently, rest defaults
|
||||
to plain
|
||||
in: query
|
||||
name: type
|
||||
type: string
|
||||
produces:
|
||||
- application/json
|
||||
- text/plain
|
||||
responses:
|
||||
"200":
|
||||
description: OK
|
||||
schema:
|
||||
$ref: '#/definitions/api.RandomQuoteJSON'
|
||||
type: object
|
||||
summary: Get a random chat message from a user
|
||||
tags:
|
||||
- user
|
||||
/channels:
|
||||
get:
|
||||
produces:
|
||||
- application/json
|
||||
responses:
|
||||
"200":
|
||||
description: OK
|
||||
schema:
|
||||
$ref: '#/definitions/api.RandomQuoteJSON'
|
||||
type: object
|
||||
"500":
|
||||
description: Internal Server Error
|
||||
schema:
|
||||
$ref: '#/definitions/api.ErrorResponse'
|
||||
type: object
|
||||
summary: Get all joined channels
|
||||
tags:
|
||||
- bot
|
||||
swagger: "2.0"
|
||||
|
|
2
main.go
2
main.go
|
@ -55,7 +55,7 @@ func main() {
|
|||
archiver := archiver.NewArchiver(cfg.LogsDirectory)
|
||||
go archiver.Boot()
|
||||
|
||||
apiServer := api.NewServer(cfg.LogsDirectory, cfg.ListenAddress, &fileLogger, &helixClient)
|
||||
apiServer := api.NewServer(cfg.LogsDirectory, cfg.ListenAddress, &fileLogger, &helixClient, cfg.Channels)
|
||||
go apiServer.Init()
|
||||
|
||||
bot := bot.NewBot(cfg.Admin, cfg.Username, cfg.OAuth, &startTime, &helixClient, &fileLogger)
|
||||
|
|
Loading…
Add table
Reference in a new issue