Skip to content

Commit

Permalink
use newJellyfin instead of constructor method
Browse files Browse the repository at this point in the history
  • Loading branch information
hrfee committed Aug 30, 2020
1 parent 072776c commit 6e3d5da
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
5 changes: 3 additions & 2 deletions jfapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ func (jf *Jellyfin) timeoutHandler() {
}
}

func (jf *Jellyfin) init(server, client, version, device, deviceId string) error {
func newJellyfin(server, client, version, device, deviceId string) (*Jellyfin, error) {
jf := &Jellyfin{}
jf.server = server
jf.client = client
jf.version = version
Expand Down Expand Up @@ -84,7 +85,7 @@ func (jf *Jellyfin) init(server, client, version, device, deviceId string) error
}
jf.cacheLength = 30
jf.cacheExpiry = time.Now()
return nil
return jf, nil
}

func (jf *Jellyfin) authenticate(username, password string) (map[string]interface{}, int, error) {
Expand Down
8 changes: 4 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ type appContext struct {
jellyfinLogin bool
users []User
invalidTokens []string
jf Jellyfin
authJf Jellyfin
jf *Jellyfin
authJf *Jellyfin
datePattern string
timePattern string
storage Storage
Expand Down Expand Up @@ -266,14 +266,14 @@ func main() {
}

server := app.config.Section("jellyfin").Key("server").String()
app.jf.init(server, "jfa-go", app.version, "hrfee-arch", "hrfee-arch")
app.jf, _ = newJellyfin(server, "jfa-go", app.version, "hrfee-arch", "hrfee-arch")
var status int
_, status, err = app.jf.authenticate(app.config.Section("jellyfin").Key("username").String(), app.config.Section("jellyfin").Key("password").String())
if status != 200 || err != nil {
app.err.Fatalf("Failed to authenticate with Jellyfin @ %s: Code %d", server, status)
}
app.info.Printf("Authenticated with %s", server)
app.authJf.init(server, "jfa-go", app.version, "auth", "auth")
app.authJf, _ = newJellyfin(server, "jfa-go", app.version, "auth", "auth")

app.loadStrftime()

Expand Down
3 changes: 1 addition & 2 deletions setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ type testReq struct {
func (app *appContext) TestJF(gc *gin.Context) {
var req testReq
gc.BindJSON(&req)
tempjf := Jellyfin{}
tempjf.init(req.Host, "jfa-go-setup", app.version, "auth", "auth")
tempjf, _ := newJellyfin(req.Host, "jfa-go-setup", app.version, "auth", "auth")
tempjf.noFail = true
_, status, err := tempjf.authenticate(req.Username, req.Password)
if !(status == 200 || status == 204) || err != nil {
Expand Down

0 comments on commit 6e3d5da

Please sign in to comment.