Commit 416e72a1 authored by Simon Kirsten's avatar Simon Kirsten
Browse files

Removed code.fbi.h-da.de prefix from package path

parent 8d90e0e7
......@@ -8,15 +8,30 @@ import (
"github.com/urfave/cli"
"code.fbi.h-da.de/simons-nzse-2/stream-tv/internal/api"
"code.fbi.h-da.de/simons-nzse-2/stream-tv/internal/util"
"code.fbi.h-da.de/simons-nzse-2/stream-tv/internal/website"
"stream-tv/internal/api"
"stream-tv/internal/util"
"stream-tv/internal/website"
"stream-tv/pkg/twitch"
)
const (
docURL = "https://simons-nzse-2.h-da.io/stream-tv/server/"
)
var (
// version will automatically be set by the CI pipeline.
version = "unknown"
)
func init() {
// The CI pipeline automatically sets twitch.ClientID to the projects client id.
// If you want to use your own set the TWITCH_CLIENT_ID environment variable.
if clientID := os.Getenv("TWITCH_CLIENT_ID"); clientID != "" {
twitch.ClientID = clientID
}
}
func main() {
app := cli.NewApp()
......@@ -28,9 +43,7 @@ func main() {
app.Usage = "Stream TV Server " + docURL
app.HideHelp = true
// TODO: we can embed the version either with git tags in the CI pipeline or just hardcode it
// for now just hide
app.HideVersion = true
app.Version = version
app.Flags = []cli.Flag{
cli.IntFlag{
......
......@@ -9,7 +9,7 @@ import (
"github.com/JamesStewy/sse"
"github.com/hashicorp/go-multierror"
"code.fbi.h-da.de/simons-nzse-2/stream-tv/internal/util"
"stream-tv/internal/util"
)
// tvState struct defines the state of the TV.
......@@ -21,7 +21,7 @@ type tvState struct {
ShowChat bool `json:"show_chat"`
}
// state is the actuall current state of the TV.
// state is the actual current state of the TV.
// It is initialized with default values.
var state = tvState{
LargeChannel: nil,
......@@ -33,7 +33,7 @@ var state = tvState{
// clients holds the clients that are connected to the event handler. It is used to broadcast state changes to all SSE (Server-Sent Events) clients.
// Note: the only reason we use a sse.Client => bool map is that we can call *delete* with the client as key. The actual bool value that is stored holds no significance whatsoever.
// This is basically a *set*.
// This is basically a *set* in go.
var clients map[*sse.Client]bool = make(map[*sse.Client]bool)
// stateHandleFunc updated the state based on the query string.
......
......@@ -4,10 +4,12 @@ import (
"net/http"
"strings"
"code.fbi.h-da.de/simons-nzse-2/stream-tv/internal/util"
"code.fbi.h-da.de/simons-nzse-2/stream-tv/pkg/twitch"
"stream-tv/internal/util"
"stream-tv/pkg/twitch"
)
// TODO: this file lacks documentation. It is pretty self explanatory though.
func gamesTopHandleFunc(w http.ResponseWriter, r *http.Request) {
response, err := twitch.GetTopGames()
......@@ -83,7 +85,7 @@ func streamsFeaturedHandleFunc(w http.ResponseWriter, r *http.Request) {
}
}
// TwitchHandler returns a http.Handler that serves requests for the /twitch backend
// TwitchHandler returns a http.Handler that serves requests for the /twitch backend.
func TwitchHandler() http.Handler {
mux := http.NewServeMux()
......
......@@ -40,6 +40,42 @@ func ServeError(w http.ResponseWriter, err error) {
http.Error(w, err.Error(), http.StatusInternalServerError)
}
// GetOutboundIP returns the outbound IP of this device.
// It is adapted from https://stackoverflow.com/a/37382208/2607571
// It works by creating an UDP socket to an arbitrary IP and port.
// As UDP is connection-less it does not send any packets until a Send call.
// This way we can get the local address without creating any connections.
func GetOutboundIP() (net.IP, error) {
conn, err := net.Dial("udp", "1.1.1.1:80")
if err != nil {
return nil, err
}
defer conn.Close()
localAddr := conn.LocalAddr().(*net.UDPAddr)
return localAddr.IP, nil
}
// OpenBrowser opens the system's default browser to the given url.
// Currently supported: linux, windows and darwin (macOS).
// From https://gist.github.com/hyg/9c4afcd91fe24316cbf0
func OpenBrowser(url string) (err error) {
switch runtime.GOOS {
case "linux":
err = exec.Command("xdg-open", url).Start()
case "windows":
err = exec.Command("rundll32", "url.dll,FileProtocolHandler", url).Start()
case "darwin":
err = exec.Command("open", url).Start()
default:
err = fmt.Errorf("unsupported platform")
}
return
}
// Info: The following two definitions are legacy and are currently not used.
// ListeningAddress represents a IP address, its interface name and if it is a loopback address.
// It is used to display all addresses a socket is listening on.
type ListeningAddress struct {
......@@ -89,37 +125,3 @@ func GetListeningAddresses() (addresses []ListeningAddress, err error) {
}
return
}
// GetOutboundIP returns the outbound IP of this device.
// It is adapted from https://stackoverflow.com/a/37382208/2607571
// It works by creating an UDP socket to an arbitrary IP and port.
// As UDP is connection-less it does not send any packets until a Send call.
// This way we can get the local address without creating any connections.
func GetOutboundIP() (net.IP, error) {
conn, err := net.Dial("udp", "1.1.1.1:80")
if err != nil {
return nil, err
}
defer conn.Close()
localAddr := conn.LocalAddr().(*net.UDPAddr)
return localAddr.IP, nil
}
// OpenBrowser opens the system's default browser to the given url.
// Currently supported: linux, windows and darwin (macOS).
// From https://gist.github.com/hyg/9c4afcd91fe24316cbf0
func OpenBrowser(url string) (err error) {
switch runtime.GOOS {
case "linux":
err = exec.Command("xdg-open", url).Start()
case "windows":
err = exec.Command("rundll32", "url.dll,FileProtocolHandler", url).Start()
case "darwin":
err = exec.Command("open", url).Start()
default:
err = fmt.Errorf("unsupported platform")
}
return
}
......@@ -4,8 +4,6 @@ import "net/url"
// twitchGame is the structure for games that we get from twitch.
type twitchGame struct {
// Viewers int `json:"viewers"`
// Game struct {
Name string `json:"name"`
Box struct {
Large string `json:"large"`
......@@ -14,8 +12,8 @@ type twitchGame struct {
Logo struct {
Large string `json:"large"`
} `json:"logo"`
Popularity int `json:"popularity"`
// }
}
// Game is the structure for games that we return to the user.
......
......@@ -16,7 +16,7 @@ var ClientID string
// Request requests the give twitch api kraken endpoint.
func Request(endpoint string, query url.Values, output interface{}) error {
if ClientID == "" {
return errors.New("Twitch ClientID is empty")
return errors.New("Twitch ClientID is not set")
}
query.Set("limit", "100")
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment