golint
This commit is contained in:
parent
32a1ca955a
commit
d844432641
@ -39,7 +39,7 @@ func (app *Bouquins) NewLoginModel(req *http.Request) *LoginModel {
|
||||
// OAuth2Provider allows to get a user from an OAuth2 token
|
||||
type OAuth2Provider interface {
|
||||
GetUser(token *oauth2.Token) (string, error)
|
||||
Config(conf *BouquinsConf) *oauth2.Config
|
||||
Config(conf *Conf) *oauth2.Config
|
||||
Name() string
|
||||
Label() string
|
||||
Icon() string
|
||||
|
@ -65,14 +65,14 @@ const (
|
||||
URLCalibre = "/calibre/"
|
||||
)
|
||||
|
||||
// BouquinsConf App configuration
|
||||
type BouquinsConf struct {
|
||||
// Conf App configuration
|
||||
type Conf struct {
|
||||
BindAddress string `json:"bind-address"`
|
||||
DbPath string `json:"db-path"`
|
||||
CalibrePath string `json:"calibre-path"`
|
||||
Prod bool `json:"prod"`
|
||||
CookieSecret string `json:"cookie-secret"`
|
||||
ExternalUrl string `json:"external-url"`
|
||||
ExternalURL string `json:"external-url"`
|
||||
ProvidersConf []ProviderConf `json:"providers"`
|
||||
}
|
||||
|
||||
|
@ -39,7 +39,8 @@ func (p GithubProvider) Icon() string {
|
||||
return "githubicon"
|
||||
}
|
||||
|
||||
func (p GithubProvider) Config(conf *BouquinsConf) *oauth2.Config {
|
||||
// Config returns OAuth configuration for this provider
|
||||
func (p GithubProvider) Config(conf *Conf) *oauth2.Config {
|
||||
for _, c := range conf.ProvidersConf {
|
||||
if c.Name == p.Name() {
|
||||
return &oauth2.Config{
|
||||
|
@ -13,10 +13,10 @@ import (
|
||||
// GoogleProvider implements OAuth2 client with google account
|
||||
type GoogleProvider string
|
||||
|
||||
type GoogleTokenInfo struct {
|
||||
type googleTokenInfo struct {
|
||||
IssuedTo string `json:"issued_to"`
|
||||
Audience string `json:"audience"`
|
||||
UserId string `json:"user_id"`
|
||||
UserID string `json:"user_id"`
|
||||
Scope string `json:"scope"`
|
||||
ExpiresIn int64 `json:"expires_in"`
|
||||
Email string `json:"email"`
|
||||
@ -43,7 +43,8 @@ func (p GoogleProvider) Icon() string {
|
||||
return "googleicon"
|
||||
}
|
||||
|
||||
func (p GoogleProvider) Config(conf *BouquinsConf) *oauth2.Config {
|
||||
// Config returns OAuth configuration for this provider
|
||||
func (p GoogleProvider) Config(conf *Conf) *oauth2.Config {
|
||||
for _, c := range conf.ProvidersConf {
|
||||
if c.Name == p.Name() {
|
||||
return &oauth2.Config{
|
||||
@ -51,7 +52,7 @@ func (p GoogleProvider) Config(conf *BouquinsConf) *oauth2.Config {
|
||||
ClientSecret: c.ClientSecret,
|
||||
Scopes: []string{"https://www.googleapis.com/auth/userinfo.email"},
|
||||
Endpoint: google.Endpoint,
|
||||
RedirectURL: conf.ExternalUrl + URLCallback,
|
||||
RedirectURL: conf.ExternalURL + URLCallback,
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -60,7 +61,6 @@ func (p GoogleProvider) Config(conf *BouquinsConf) *oauth2.Config {
|
||||
|
||||
// GetUser returns github primary email
|
||||
func (p GoogleProvider) GetUser(token *oauth2.Token) (string, error) {
|
||||
// POST https://www.googleapis.com/oauth2/v2/tokeninfo access_token
|
||||
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 {
|
||||
@ -68,7 +68,7 @@ func (p GoogleProvider) GetUser(token *oauth2.Token) (string, error) {
|
||||
return "", fmt.Errorf("Authentification error")
|
||||
}
|
||||
dec := json.NewDecoder(apiRes.Body)
|
||||
var tokenInfo GoogleTokenInfo
|
||||
var tokenInfo googleTokenInfo
|
||||
err = dec.Decode(&tokenInfo)
|
||||
if err != nil {
|
||||
log.Println("Error reading google API response", err)
|
||||
|
7
main.go
7
main.go
@ -18,8 +18,8 @@ import (
|
||||
var db *sql.DB
|
||||
|
||||
// ReadConfig loads configuration file and initialize default value
|
||||
func ReadConfig() (*bouquins.BouquinsConf, error) {
|
||||
conf := new(bouquins.BouquinsConf)
|
||||
func ReadConfig() (*bouquins.Conf, error) {
|
||||
conf := new(bouquins.Conf)
|
||||
confPath := "bouquins.json"
|
||||
if len(os.Args) > 1 {
|
||||
confPath = os.Args[1]
|
||||
@ -45,7 +45,7 @@ func ReadConfig() (*bouquins.BouquinsConf, error) {
|
||||
return conf, err
|
||||
}
|
||||
|
||||
func initApp() *bouquins.BouquinsConf {
|
||||
func initApp() *bouquins.Conf {
|
||||
log.SetFlags(log.LstdFlags | log.Lshortfile)
|
||||
conf, err := ReadConfig()
|
||||
if err != nil {
|
||||
@ -65,7 +65,6 @@ func initApp() *bouquins.BouquinsConf {
|
||||
for _, provider := range bouquins.Providers {
|
||||
oauthConf[provider.Name()] = provider.Config(conf)
|
||||
}
|
||||
// FIXME constructor, conf cookies secret
|
||||
app := &bouquins.Bouquins{Tpl: tpl, DB: db, OAuthConf: oauthConf, Cookies: sessions.NewCookieStore([]byte(conf.CookieSecret))}
|
||||
err = app.PrepareAll()
|
||||
if err != nil {
|
||||
|
Loading…
Reference in New Issue
Block a user