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"
|
const twitchUrl = "https://gql.twitch.tv/gql"
|
||||||
|
|
||||||
|
var language string = "en"
|
||||||
|
|
||||||
// useful funcs
|
// useful funcs
|
||||||
|
func SetLanguage(code string) {
|
||||||
|
language = code
|
||||||
|
}
|
||||||
|
|
||||||
func call(url, method string, body io.Reader) (*http.Response, error) {
|
func call(url, method string, body io.Reader) (*http.Response, error) {
|
||||||
req, err := http.NewRequest(method, url, body)
|
req, err := http.NewRequest(method, url, body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return req.Response, err
|
return req.Response, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
req.Header.Add("Accept-Language", language)
|
||||||
req.Header.Add("Client-Id", "ue6666qo983tsx6so1t0vnawi233wa")
|
req.Header.Add("Client-Id", "ue6666qo983tsx6so1t0vnawi233wa")
|
||||||
resp, err := http.DefaultClient.Do(req)
|
resp, err := http.DefaultClient.Do(req)
|
||||||
return resp, err
|
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) {
|
func parseResponse(payload []TwitchPayload) (response *[]structs.TwitchApiResponse, body []byte, err error) {
|
||||||
json_data, err := json.Marshal(payload)
|
json_data, err := json.Marshal(payload)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
6
main.go
6
main.go
|
@ -4,6 +4,7 @@ import (
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"safetwitch-backend/extractor/chat"
|
"safetwitch-backend/extractor/chat"
|
||||||
|
"safetwitch-backend/extractor/twitch"
|
||||||
"safetwitch-backend/routes"
|
"safetwitch-backend/routes"
|
||||||
|
|
||||||
"strings"
|
"strings"
|
||||||
|
@ -40,6 +41,10 @@ func CORS() gin.HandlerFunc {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func setLang(c *gin.Context) {
|
||||||
|
twitch.SetLanguage(c.GetHeader("Accept-Language"))
|
||||||
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
log.Println("Starting Safetwitch...")
|
log.Println("Starting Safetwitch...")
|
||||||
// check for env
|
// check for env
|
||||||
|
@ -54,6 +59,7 @@ func main() {
|
||||||
|
|
||||||
go chat.BeginTwitchChatConnection()
|
go chat.BeginTwitchChatConnection()
|
||||||
|
|
||||||
|
router.Use(setLang)
|
||||||
router.Use(ErrorHandler)
|
router.Use(ErrorHandler)
|
||||||
routes.SetRoutes(router)
|
routes.SetRoutes(router)
|
||||||
router.NoRoute(notFoundHandler)
|
router.NoRoute(notFoundHandler)
|
||||||
|
|
Loading…
Reference in a new issue