fix lint, vet

This commit is contained in:
Meutel 2019-09-11 17:11:43 +02:00
parent 641e4e2093
commit 1b9a4a6614
5 changed files with 11 additions and 5 deletions

View File

@ -493,6 +493,7 @@ func (app *Bouquins) IndexPage(res http.ResponseWriter, req *http.Request) error
return app.render(res, tplIndex, model) return app.render(res, tplIndex, model)
} }
// CalibreFileServer serves files from calibre path
func (app *Bouquins) CalibreFileServer() http.Handler { func (app *Bouquins) CalibreFileServer() http.Handler {
calibre := app.Conf.CalibrePath calibre := app.Conf.CalibrePath
handler := http.StripPrefix(URLCalibre, http.FileServer(http.Dir(calibre))) handler := http.StripPrefix(URLCalibre, http.FileServer(http.Dir(calibre)))

View File

@ -9,7 +9,7 @@ import (
"golang.org/x/oauth2" "golang.org/x/oauth2"
) )
// GithubProvider implements OAuth2 client with github.com // GiteaProvider implements OAuth2 client with custom gitea server
type GiteaProvider string type GiteaProvider string
type giteaProfile struct { type giteaProfile struct {
@ -61,7 +61,11 @@ func (p GiteaProvider) Config(conf *Conf) *oauth2.Config {
ClientID: c.ClientID, ClientID: c.ClientID,
ClientSecret: c.ClientSecret, ClientSecret: c.ClientSecret,
RedirectURL: conf.ExternalURL + "/callback", RedirectURL: conf.ExternalURL + "/callback",
Endpoint: oauth2.Endpoint{c.AuthURL, c.TokenURL, oauth2.AuthStyleAutoDetect}, Endpoint: oauth2.Endpoint{
AuthURL: c.AuthURL,
TokenURL: c.TokenURL,
AuthStyle: oauth2.AuthStyleAutoDetect,
},
} }
} }
} }
@ -75,11 +79,11 @@ func (p GiteaProvider) GetUser(app *Bouquins, token *oauth2.Token) (string, erro
apiReq.Header.Add("Authorization", "token "+token.AccessToken) apiReq.Header.Add("Authorization", "token "+token.AccessToken)
client := &http.Client{} client := &http.Client{}
response, err := client.Do(apiReq) response, err := client.Do(apiReq)
defer response.Body.Close()
if err != nil { if err != nil {
log.Println("Auth error", err) log.Println("Auth error", err)
return "", fmt.Errorf("Authentification error") return "", fmt.Errorf("Authentification error")
} }
defer response.Body.Close()
dec := json.NewDecoder(response.Body) dec := json.NewDecoder(response.Body)
var profile giteaProfile var profile giteaProfile

View File

@ -61,11 +61,11 @@ func (p GithubProvider) GetUser(app *Bouquins, token *oauth2.Token) (string, err
apiReq.Header.Add("Authorization", "token "+token.AccessToken) apiReq.Header.Add("Authorization", "token "+token.AccessToken)
client := &http.Client{} client := &http.Client{}
response, err := client.Do(apiReq) response, err := client.Do(apiReq)
defer response.Body.Close()
if err != nil { if err != nil {
log.Println("Auth error", err) log.Println("Auth error", err)
return "", fmt.Errorf("Authentification error") return "", fmt.Errorf("Authentification error")
} }
defer response.Body.Close()
dec := json.NewDecoder(response.Body) dec := json.NewDecoder(response.Body)
var emails []githubEmail var emails []githubEmail

View File

@ -62,11 +62,11 @@ func (p GoogleProvider) Config(conf *Conf) *oauth2.Config {
// GetUser returns github primary email // GetUser returns github primary email
func (p GoogleProvider) GetUser(app *Bouquins, token *oauth2.Token) (string, error) { func (p GoogleProvider) GetUser(app *Bouquins, token *oauth2.Token) (string, error) {
apiRes, err := http.Post("https://www.googleapis.com/oauth2/v2/tokeninfo?access_token="+token.AccessToken, "application/json", nil) apiRes, err := http.Post("https://www.googleapis.com/oauth2/v2/tokeninfo?access_token="+token.AccessToken, "application/json", nil)
defer apiRes.Body.Close()
if err != nil { if err != nil {
log.Println("Auth error", err) log.Println("Auth error", err)
return "", fmt.Errorf("Authentification error") return "", fmt.Errorf("Authentification error")
} }
defer apiRes.Body.Close()
dec := json.NewDecoder(apiRes.Body) dec := json.NewDecoder(apiRes.Body)
var tokenInfo googleTokenInfo var tokenInfo googleTokenInfo
err = dec.Decode(&tokenInfo) err = dec.Decode(&tokenInfo)

1
go.sum
View File

@ -16,6 +16,7 @@ golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73r
golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e h1:bRhVy7zSSasaqNksaRZiA5EEI+Ei4I1nO5Jh72wfHlg= golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e h1:bRhVy7zSSasaqNksaRZiA5EEI+Ei4I1nO5Jh72wfHlg=
golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
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/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45 h1:SVwTIAaPC2U/AvvLNZ2a7OVsmBpC8L5BlwK1whH3hm0= 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/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=