MCPcopy
hub / github.com/perkeep/perkeep / New

Function New

pkg/client/client.go:165–207  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

163// By default, with no options, it uses the client as configured in
164// the environment or default configuration files.
165func 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
209func (c *Client) setDefaultHTTPClient() {
210 if c.httpClient == nil {

Callers 12

setupClientFunction · 0.92
newFromConfigFunction · 0.92
ClientFunction · 0.92
makeThingsMethod · 0.92
envSecretRingFileFunction · 0.92
RunCommandMethod · 0.92
storageFromParamMethod · 0.92
syncAllMethod · 0.92
TestServerOfNameFunction · 0.70
NewOrFailFunction · 0.70
NewPathClientMethod · 0.70
NewFromShareRootFunction · 0.70

Calls 7

setDefaultHTTPClientMethod · 0.95
SetupAuthMethod · 0.95
UserClientConfigPathFunction · 0.92
isURLOrHostPortFunction · 0.85
getServerFunction · 0.85
modifyClientMethod · 0.65
FatalfMethod · 0.65

Tested by 1

TestServerOfNameFunction · 0.56