mirror of
https://codeberg.org/SafeTwitch/safetwitch-backend.git
synced 2024-12-22 05:02:58 -05:00
Complete translation support
This commit is contained in:
parent
45f77b7a3b
commit
367b745268
2 changed files with 13 additions and 14 deletions
|
@ -15,32 +15,25 @@ import (
|
|||
|
||||
const twitchUrl = "https://gql.twitch.tv/gql"
|
||||
|
||||
var language string = "en"
|
||||
|
||||
// useful funcs
|
||||
func SetLanguage(code string) {
|
||||
language = code
|
||||
}
|
||||
|
||||
func call(url, method string, body io.Reader) (*http.Response, error) {
|
||||
req, err := http.NewRequest(method, url, body)
|
||||
if err != nil {
|
||||
return req.Response, err
|
||||
}
|
||||
|
||||
req.Header.Add("Accept-Language", language)
|
||||
req.Header.Add("Client-Id", "ue6666qo983tsx6so1t0vnawi233wa")
|
||||
resp, err := http.DefaultClient.Do(req)
|
||||
return resp, err
|
||||
}
|
||||
|
||||
func getResponse(url string) ([]byte, error) {
|
||||
resp, err := http.Get(url)
|
||||
if err != nil {
|
||||
return []byte{}, err
|
||||
}
|
||||
|
||||
body, err := io.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return []byte{}, err
|
||||
}
|
||||
|
||||
return body, nil
|
||||
}
|
||||
|
||||
func parseResponse(payload []TwitchPayload) (response *[]structs.TwitchApiResponse, body []byte, err error) {
|
||||
json_data, err := json.Marshal(payload)
|
||||
if err != nil {
|
||||
|
|
6
main.go
6
main.go
|
@ -4,6 +4,7 @@ import (
|
|||
"log"
|
||||
"os"
|
||||
"safetwitch-backend/extractor/chat"
|
||||
"safetwitch-backend/extractor/twitch"
|
||||
"safetwitch-backend/routes"
|
||||
|
||||
"strings"
|
||||
|
@ -40,6 +41,10 @@ func CORS() gin.HandlerFunc {
|
|||
}
|
||||
}
|
||||
|
||||
func setLang(c *gin.Context) {
|
||||
twitch.SetLanguage(c.GetHeader("Accept-Language"))
|
||||
}
|
||||
|
||||
func main() {
|
||||
log.Println("Starting Safetwitch...")
|
||||
// check for env
|
||||
|
@ -54,6 +59,7 @@ func main() {
|
|||
|
||||
go chat.BeginTwitchChatConnection()
|
||||
|
||||
router.Use(setLang)
|
||||
router.Use(ErrorHandler)
|
||||
routes.SetRoutes(router)
|
||||
router.NoRoute(notFoundHandler)
|
||||
|
|
Loading…
Reference in a new issue