New returns a new Perkeep Client. By default, with no options, it uses the client as configured in the environment or default configuration files.
(opts ...ClientOption)
| 163 | // By default, with no options, it uses the client as configured in |
| 164 | // the environment or default configuration files. |
| 165 | func New(opts ...ClientOption) (*Client, error) { |
| 166 | c := &Client{ |
| 167 | haveCache: noHaveCache{}, |
| 168 | Logger: log.New(os.Stderr, "", log.Ldate|log.Ltime), |
| 169 | authMode: auth.None{}, |
| 170 | } |
| 171 | for _, v := range opts { |
| 172 | v.modifyClient(c) |
| 173 | } |
| 174 | if c.sto != nil && len(opts) > 1 { |
| 175 | return nil, errors.New("use of OptionUseStorageClient precludes use of any other options") |
| 176 | } |
| 177 | |
| 178 | if c.noExtConfig { |
| 179 | c.setDefaultHTTPClient() |
| 180 | return c, nil |
| 181 | } |
| 182 | |
| 183 | if c.server != "" { |
| 184 | if !isURLOrHostPort(c.server) { |
| 185 | configOnce.Do(parseConfig) |
| 186 | serverConf, ok := config.Servers[c.server] |
| 187 | if !ok { |
| 188 | log.Fatalf("%q looks like a server alias, but no such alias found in config at %v", c.server, osutil.UserClientConfigPath()) |
| 189 | } |
| 190 | c.server = serverConf.Server |
| 191 | } |
| 192 | c.setDefaultHTTPClient() |
| 193 | return c, nil |
| 194 | } |
| 195 | |
| 196 | var err error |
| 197 | c.server, err = getServer() |
| 198 | if err != nil { |
| 199 | return nil, err |
| 200 | } |
| 201 | err = c.SetupAuth() |
| 202 | if err != nil { |
| 203 | return nil, err |
| 204 | } |
| 205 | c.setDefaultHTTPClient() |
| 206 | return c, nil |
| 207 | } |
| 208 | |
| 209 | func (c *Client) setDefaultHTTPClient() { |
| 210 | if c.httpClient == nil { |