get select edit, read, and delete working
This commit is contained in:
parent
b680a2f5d7
commit
99548e67b7
5 changed files with 62 additions and 13 deletions
28
gemlog/db.go
28
gemlog/db.go
|
|
@ -76,6 +76,34 @@ func listGemLogs(config *Config) ([]GemlogListEntry, error) {
|
|||
return entries, nil
|
||||
}
|
||||
|
||||
func DeleteGemlogEntry(config *Config, id string) error {
|
||||
url := fmt.Sprintf("%s:%d/gemlog/%s", config.CouchDB.Host, config.CouchDB.Port, id)
|
||||
req, err := http.NewRequest("DELETE", 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))
|
||||
req.Header.Add("content-type", "application/json")
|
||||
|
||||
res, err := http.DefaultClient.Do(req)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to send request: %w", err)
|
||||
}
|
||||
defer res.Body.Close()
|
||||
|
||||
body, err := io.ReadAll(res.Body)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to read response body: %w", err)
|
||||
}
|
||||
|
||||
if res.StatusCode < 200 || res.StatusCode >= 300 {
|
||||
return fmt.Errorf("unexpected status code %d: %s", res.StatusCode, string(body))
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func SaveGemlogEntry(config *Config, entry *GemlogEntry) error {
|
||||
url := fmt.Sprintf("%s:%d/gemlog/", config.CouchDB.Host, config.CouchDB.Port)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue