Cleanup string usage

This commit is contained in:
Zoe Roux 2024-01-11 23:15:54 +01:00
parent 570f08755d
commit 8805f0f804
5 changed files with 20 additions and 16 deletions

View File

@ -4,7 +4,7 @@ go 1.20
require ( require (
github.com/golang-jwt/jwt v3.2.2+incompatible // indirect github.com/golang-jwt/jwt v3.2.2+incompatible // indirect
github.com/labstack/echo/v4 v4.11.4 // indirect github.com/labstack/echo/v4 v4.11.4 // direct
github.com/labstack/gommon v0.4.2 // indirect github.com/labstack/gommon v0.4.2 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect github.com/mattn/go-isatty v0.0.20 // indirect

View File

@ -23,7 +23,7 @@ func DirectStream(c echo.Context) error {
if err != nil { if err != nil {
return err return err
} }
return c.File(*path) return c.File(path)
} }
// Get master playlist // Get master playlist
@ -47,7 +47,7 @@ func (h *Handler) GetMaster(c echo.Context) error {
return err return err
} }
ret, err := h.transcoder.GetMaster(*path, *client) ret, err := h.transcoder.GetMaster(path, client)
if err != nil { if err != nil {
return err return err
} }

View File

@ -95,3 +95,7 @@ func (fs *FileStream) IsDead() bool {
} }
return false return false
} }
func (fs *FileStream) GetMaster() string {
return ""
}

View File

@ -5,14 +5,14 @@ type Transcoder struct {
streams map[string]FileStream streams map[string]FileStream
} }
func (t *Transcoder) GetMaster(path string, client string) (*string, error) { func (t *Transcoder) GetMaster(path string, client string) (string, error) {
stream, ok := t.streams[path] stream, ok := t.streams[path]
if !ok { if !ok {
stream, err := NewFileStream(path) stream, err := NewFileStream(path)
if err != nil { if err != nil {
return nil, err return "", err
} }
t.streams[path] = *stream t.streams[path] = *stream
} }
return &stream.GetMaster() return stream.GetMaster(), nil
} }

View File

@ -18,29 +18,29 @@ type Item struct {
Path string `json:"path"` Path string `json:"path"`
} }
func GetPath(resource string, slug string) (*string, error) { func GetPath(resource string, slug string) (string, error) {
url := os.Getenv("API_URL") url := os.Getenv("API_URL")
if url == "" { if url == "" {
url = "http://back:5000" url = "http://back:5000"
} }
key := os.Getenv("KYOO_APIKEYS") key := os.Getenv("KYOO_APIKEYS")
if key == "" { if key == "" {
return nil, errors.New("missing api keys") return "", errors.New("missing api keys")
} }
key = strings.Split(key, ",")[0] key = strings.Split(key, ",")[0]
req, err := http.NewRequest("GET", strings.Join([]string{url, resource, slug}, "/"), nil) req, err := http.NewRequest("GET", strings.Join([]string{url, resource, slug}, "/"), nil)
if err != nil { if err != nil {
return nil, err return "", err
} }
req.Header.Set("X-API-KEY", key) req.Header.Set("X-API-KEY", key)
res, err := client.Do(req) res, err := client.Do(req)
if err != nil { if err != nil {
return nil, err return "", err
} }
if res.StatusCode != 200 { if res.StatusCode != 200 {
return nil, echo.NewHTTPError( return "", echo.NewHTTPError(
http.StatusNotAcceptable, http.StatusNotAcceptable,
fmt.Sprintf("No %s found with the slug %s.", resource, slug), fmt.Sprintf("No %s found with the slug %s.", resource, slug),
) )
@ -50,18 +50,18 @@ func GetPath(resource string, slug string) (*string, error) {
ret := Item{} ret := Item{}
err = json.NewDecoder(res.Body).Decode(&ret) err = json.NewDecoder(res.Body).Decode(&ret)
if err != nil { if err != nil {
return nil, err return "", err
} }
return &ret.Path, nil return ret.Path, nil
} }
func GetClientId(c echo.Context) (*string, error) { func GetClientId(c echo.Context) (string, error) {
key := c.Request().Header.Get("X-CLIENT-ID") key := c.Request().Header.Get("X-CLIENT-ID")
if key == "" { if key == "" {
return nil, errors.New("Missing client id. Please specify the X-CLIENT-ID header to a guid constant for the lifetime of the player (but unique per instance).") return "", errors.New("missing client id. Please specify the X-CLIENT-ID header to a guid constant for the lifetime of the player (but unique per instance)")
} }
return &key, nil return key, nil
} }
func ErrorHandler(err error, c echo.Context) { func ErrorHandler(err error, c echo.Context) {