add db check fn and ignore debug logs
This commit is contained in:
parent
ccf39d829a
commit
eb2191045e
4 changed files with 21 additions and 593 deletions
19
gemlog/db.go
19
gemlog/db.go
|
|
@ -114,3 +114,22 @@ func SaveGemlogEntry(config *Config, entry *GemlogEntry) error {
|
|||
|
||||
return nil
|
||||
}
|
||||
|
||||
func CheckDBConnection(config *Config) error {
|
||||
url := fmt.Sprintf("%s:%d/gemlog/", config.CouchDB.Host, config.CouchDB.Port)
|
||||
req, err := http.NewRequest("GET", url, nil)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to create request: %w", err)
|
||||
}
|
||||
req.Header.Add("authorization", genBasicAuthHeader(config.CouchDB.User, config.CouchDB.Password))
|
||||
res, err := http.DefaultClient.Do(req)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to send request: %w", err)
|
||||
}
|
||||
defer res.Body.Close()
|
||||
|
||||
if res.StatusCode == 200 {
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("unexpected status code %d", res.StatusCode)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue