Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ go 1.16
require (
github.com/sirupsen/logrus v1.8.1
github.com/spf13/viper v1.7.1
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45
)
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -216,9 +216,11 @@ golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn
golang.org/x/net v0.0.0-20190501004415-9ce7a6920f09/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190503192946-f4e77d36d62c/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190603091049-60506f45cf65/go.mod h1:HSz+uSET+XFnRR8LxR5pz3Of3rY3CfYBVs4xY44aLks=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859 h1:R/3boaszxrf1GEUWTVDzSKVwLmSJpwZ1yqXm8j0v2QI=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45 h1:SVwTIAaPC2U/AvvLNZ2a7OVsmBpC8L5BlwK1whH3hm0=
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
Expand Down
5 changes: 3 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ package main

import (
"github.com/VladyslavLukyanenko/GopherAlert/configs"
"github.com/VladyslavLukyanenko/GopherAlert/twitchAPI"
log "github.com/sirupsen/logrus"
)


func main() {
configs.ReadConfig()
setupLogger()
twitchAPI.GetTwitchChannelStatus("ArQuel")
}

func setupLogger() {
Expand All @@ -18,4 +19,4 @@ func setupLogger() {
} else {
log.SetLevel(lvl)
}
}
}
33 changes: 33 additions & 0 deletions twitchAPI/twitchCommands.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package twitchAPI

import (
"fmt"
"io/ioutil"
"log"
"net/http"
"os"
)

var ENDPOINT_URL = "https://api.twitch.tv/helix/streams/?user_login="
var TOKEN = GetTwitchToken()
var CLIENT_ID = clientID

func GetTwitchChannelStatus(twitchLogin string) string {

req, _ := http.NewRequest(http.MethodGet, ENDPOINT_URL+twitchLogin, nil)
req.Header.Add("Client-ID", CLIENT_ID)
req.Header.Add("Authorization", "Bearer " + TOKEN)

response, err := http.DefaultClient.Do(req)
if err != nil {
fmt.Print(err.Error())
os.Exit(1)
}

responseData, err := ioutil.ReadAll(response.Body)
if err != nil {
log.Fatal(err)
}
fmt.Println(string(responseData))
return (string(responseData))
}
31 changes: 31 additions & 0 deletions twitchAPI/twitchCredentials.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package twitchAPI

import (
"context"
"fmt"
"log"

"golang.org/x/oauth2/clientcredentials"
"golang.org/x/oauth2/twitch"

)

var (
clientID = "bug2jjuz0dkbmt1ybs1af6kh1jm968"
clientSecret = "f3yeu9mojrxchu6c2pxtw0lce6d7dt"
oauth2Config *clientcredentials.Config
)

func GetTwitchToken() string {
oauth2Config = &clientcredentials.Config{
ClientID: clientID,
ClientSecret: clientSecret,
TokenURL: twitch.Endpoint.TokenURL,
}

token, err := oauth2Config.Token(context.Background())
if err != nil {
log.Fatal(err)
}
return token.AccessToken
}