MCPcopy Index your code
hub / github.com/syncthing/syncthing / getClient

Method getClient

cmd/syncthing/cli/client.go:44–72  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

42}
43
44func (f *apiClientFactory) getClient() (APIClient, error) {
45 // Now if the API key and address is not provided (we are not connecting to a remote instance),
46 // try to rip it out of the config.
47 if f.cfg.RawAddress == "" && f.cfg.APIKey == "" {
48 var err error
49 f.cfg, err = loadGUIConfig()
50 if err != nil {
51 return nil, err
52 }
53 } else if f.cfg.Address() == "" || f.cfg.APIKey == "" {
54 return nil, errors.New("Both --gui-address and --gui-apikey should be specified")
55 }
56
57 httpClient := http.Client{
58 Transport: &http.Transport{
59 TLSClientConfig: &tls.Config{
60 InsecureSkipVerify: true,
61 },
62 DialContext: func(_ context.Context, _, _ string) (net.Conn, error) {
63 return net.Dial(f.cfg.Network(), f.cfg.Address())
64 },
65 },
66 }
67 return &apiClient{
68 Client: httpClient,
69 cfg: f.cfg,
70 apikey: f.cfg.APIKey,
71 }, nil
72}
73
74func loadGUIConfig() (config.GUIConfiguration, error) {
75 // Load the certs and get the ID

Callers 7

emptyPostFunction · 0.80
indexDumpOutputFunction · 0.80
saveToFileFunction · 0.80
RunMethod · 0.80
RunMethod · 0.80
RunMethod · 0.80
RunMethod · 0.80

Calls 5

loadGUIConfigFunction · 0.85
NewMethod · 0.65
DialMethod · 0.65
AddressMethod · 0.45
NetworkMethod · 0.45

Tested by

no test coverage detected