MCPcopy Index your code
hub / github.com/dnote/dnote / CreateBook

Function CreateBook

pkg/cli/client/client.go:323–343  ·  view source on GitHub ↗

CreateBook creates a new book in the server

(ctx context.DnoteCtx, label string)

Source from the content-addressed store, hash-verified

321
322// CreateBook creates a new book in the server
323func CreateBook(ctx context.DnoteCtx, label string) (CreateBookResp, error) {
324 payload := CreateBookPayload{
325 Name: label,
326 }
327 b, err := json.Marshal(payload)
328 if err != nil {
329 return CreateBookResp{}, errors.Wrap(err, "marshaling payload")
330 }
331
332 res, err := doAuthorizedReq(ctx, "POST", "/v3/books", string(b), nil)
333 if err != nil {
334 return CreateBookResp{}, errors.Wrap(err, "posting a book to the server")
335 }
336
337 var resp CreateBookResp
338 if err := json.NewDecoder(res.Body).Decode(&resp); err != nil {
339 return resp, errors.Wrap(err, "decoding response payload")
340 }
341
342 return resp, nil
343}
344
345type updateBookPayload struct {
346 Name *string `json:"name"`

Callers 1

sendBooksFunction · 0.92

Calls 1

doAuthorizedReqFunction · 0.85

Tested by

no test coverage detected