rough skeleton and basic user authentication
This commit is contained in:
82
api/endpoints.go
Normal file
82
api/endpoints.go
Normal file
@@ -0,0 +1,82 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
func (server *ApiServer) loadEndpoints() {
|
||||
server.engine.GET("/ping", func(c *gin.Context) {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"message": "pong",
|
||||
})
|
||||
})
|
||||
|
||||
// info for user-end html pages
|
||||
serverInfo := ServerInfo{
|
||||
ClientID: server.conf.ClientID,
|
||||
AuthParams: TwitchAuthParams{
|
||||
ClientID: server.conf.ClientID,
|
||||
ForceVerify: false,
|
||||
RedirectURI: server.conf.RedirectURI,
|
||||
ResponseType: "code",
|
||||
Scope: []string{
|
||||
"bits:read",
|
||||
"channel:bot",
|
||||
"channel:read:goals",
|
||||
"channel:read:hype_train",
|
||||
"channel:read:polls",
|
||||
"channel:manage:polls",
|
||||
"channel:read:predictions",
|
||||
"channel:manage:predictions",
|
||||
"channel:read:redemptions",
|
||||
"channel:manage:redemptions",
|
||||
"channel:read:vips",
|
||||
"channel:moderate",
|
||||
"user:bot",
|
||||
"user:read:broadcast",
|
||||
"user:read:chat",
|
||||
"user:read:emotes",
|
||||
"user:write:chat",
|
||||
},
|
||||
State: "", // TODO make this unique per request
|
||||
},
|
||||
}
|
||||
|
||||
server.engine.GET("/info", func(c *gin.Context) {
|
||||
c.JSON(http.StatusOK, serverInfo)
|
||||
})
|
||||
|
||||
server.engine.GET("/auth", func(c *gin.Context) {
|
||||
// TODO auth response from twitch
|
||||
// parse args as TwitchAuthRespOk or TwitchAuthRespErr
|
||||
c.JSON(http.StatusOK, serverInfo)
|
||||
})
|
||||
}
|
||||
|
||||
type ServerInfo struct {
|
||||
ClientID string `json:"client_id"`
|
||||
AuthParams TwitchAuthParams `json:"auth_params"`
|
||||
}
|
||||
|
||||
type TwitchAuthParams struct {
|
||||
ClientID string `json:"client_id"`
|
||||
ForceVerify bool `json:"force_verify"`
|
||||
RedirectURI string `json:"redirect_uri"`
|
||||
ResponseType string `json:"response_type"`
|
||||
Scope []string `json:"scope"`
|
||||
State string `json:"state"`
|
||||
}
|
||||
|
||||
type TwitchAuthRespOk struct {
|
||||
Code string `json:"code"`
|
||||
Scope string `json:"scope"`
|
||||
State string `json:"state"`
|
||||
}
|
||||
|
||||
type TwitchAuthRespErr struct {
|
||||
Err string `json:"error"`
|
||||
ErrDesc string `json:"error_description"`
|
||||
State string `json:"state"`
|
||||
}
|
||||
33
api/main.go
Normal file
33
api/main.go
Normal file
@@ -0,0 +1,33 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"zomo.dev/largehadroncollider/db"
|
||||
"zomo.dev/largehadroncollider/ttv"
|
||||
"zomo.dev/largehadroncollider/util"
|
||||
)
|
||||
|
||||
func InitApiServer(conf *util.Config, dbConn *db.DBConn, twitchConn *ttv.TwitchConn) (*ApiServer, error) {
|
||||
engine := gin.Default()
|
||||
|
||||
apiServer := &ApiServer{ engine, conf, dbConn, twitchConn }
|
||||
|
||||
apiServer.loadEndpoints()
|
||||
|
||||
return apiServer, nil
|
||||
}
|
||||
|
||||
type ApiServer struct {
|
||||
engine *gin.Engine
|
||||
conf *util.Config
|
||||
db *db.DBConn
|
||||
twitch *ttv.TwitchConn
|
||||
}
|
||||
|
||||
func (server *ApiServer) Listen() {
|
||||
server.engine.Run()
|
||||
}
|
||||
|
||||
func initHTMLFiles() {
|
||||
|
||||
}
|
||||
17
api/ws/main.go
Normal file
17
api/ws/main.go
Normal file
@@ -0,0 +1,17 @@
|
||||
package ws
|
||||
|
||||
import (
|
||||
"zomo.dev/largehadroncollider/db"
|
||||
"zomo.dev/largehadroncollider/ttv"
|
||||
)
|
||||
|
||||
func InitWSServer(dbConn db.DBConn, twitchConn ttv.TwitchConn) (WSServer, error) {
|
||||
return WSServer{}, nil
|
||||
}
|
||||
|
||||
type WSServer struct {
|
||||
}
|
||||
|
||||
func (wsServer *WSServer) Listen() {
|
||||
// start web server itself
|
||||
}
|
||||
Reference in New Issue
Block a user