-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathconfig.go
60 lines (54 loc) · 1.97 KB
/
config.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package main
import (
"context"
"net/http"
"time"
"cloud.google.com/go/storage"
"github.com/kelseyhightower/envconfig"
"google.golang.org/api/option"
ghttp "google.golang.org/api/transport/http"
)
// Config represents the protodash configuration that is loaded from the
// environment.
type Config struct {
Listen string `default:":8080"`
LogLevel string `split_words:"true" default:"debug"`
ProxyTimeout time.Duration `split_words:"true" default:"10s"`
ClientTimeout time.Duration `split_words:"true" default:"2s"`
IdleConnTimeout time.Duration `split_words:"true" default:"120s"`
MaxIdleConns int `split_words:"true" default:"10"`
BaseDomain string `split_words:"true" default:"localhost:8080"`
OAuthEnabled bool `envconfig:"OAUTH_ENABLED"`
OAuthDomain string `envconfig:"OAUTH_DOMAIN"`
OAuthClientID string `envconfig:"OAUTH_CLIENT_ID"`
OAuthClientSecret string `envconfig:"OAUTH_CLIENT_SECRET"`
OAuthRedirectURI string `envconfig:"OAUTH_REDIRECT_URI"`
SessionSecret string `split_words:"true"`
ShowPrivate bool `split_words:"true"`
RedirectToLogin bool `split_words:"true"`
DefaultBucket string `split_words:"true"`
ConfigFile string `split_words:"true" default:"config.yml"`
}
// HTTPClient returns an HTTP client with the proper authentication config
// (using Google's default application credentials) and timeouts.
func (c *Config) HTTPClient() (*http.Client, error) {
baseTransport := &http.Transport{
IdleConnTimeout: c.IdleConnTimeout,
MaxIdleConns: c.MaxIdleConns,
}
transport, err := ghttp.NewTransport(
context.Background(),
baseTransport,
option.WithScopes(storage.ScopeReadOnly),
)
return &http.Client{
Timeout: c.ClientTimeout,
Transport: transport,
}, err
}
// LoadConfig loads the configuration from environment variables.
func LoadConfig() (*Config, error) {
c := &Config{}
err := envconfig.Process("protodash", c)
return c, err
}