MCPcopy
hub / github.com/perkeep/perkeep / GetAPIKey

Function GetAPIKey

internal/geocode/geocode.go:91–118  ·  view source on GitHub ↗

GetAPIKey returns the Google geocoding API key stored in the Perkeep configuration directory as google-geocode.key.

()

Source from the content-addressed store, hash-verified

89// GetAPIKey returns the Google geocoding API key stored in the Perkeep
90// configuration directory as google-geocode.key.
91func GetAPIKey() (string, error) {
92 mu.RLock()
93 key := apiKey
94 mu.RUnlock()
95 if apiKey != "" {
96 return key, nil
97 }
98 mu.Lock()
99 defer mu.Unlock()
100
101 dir, err := osutil.PerkeepConfigDir()
102 if err != nil {
103 return "", err
104 }
105 slurp, err := wkfs.ReadFile(filepath.Join(dir, apiKeyName))
106 if os.IsNotExist(err) {
107 return "", ErrNoGoogleKey
108 }
109 if err != nil {
110 return "", err
111 }
112 key = strings.TrimSpace(string(slurp))
113 if key == "" {
114 return "", ErrNoGoogleKey
115 }
116 apiKey = key
117 return key, nil
118}
119
120var ErrNoGoogleKey = errors.New("geocode: Google API key not configured, using OpenStreetMap; see https://perkeep.org/doc/geocoding")
121

Callers 2

checkGeoKeyFunction · 0.92
LookupFunction · 0.85

Calls 5

PerkeepConfigDirFunction · 0.92
LockMethod · 0.80
UnlockMethod · 0.80
RLockMethod · 0.65
RUnlockMethod · 0.65

Tested by

no test coverage detected