Documentation ¶
Index ¶
- func WithServerURL(ctx context.Context, u *url.URL) context.Context
- type Client
- type ClientOption
- type DeleteNoteNoContent
- type DeleteNoteParams
- type DraftMultipart
- func (s *DraftMultipart) GetAttachment() []ht.MultipartFile
- func (s *DraftMultipart) GetAuthor() OptString
- func (s *DraftMultipart) GetHideAttachments() OptBool
- func (s *DraftMultipart) GetText() string
- func (s *DraftMultipart) GetTitle() string
- func (s *DraftMultipart) SetAttachment(val []ht.MultipartFile)
- func (s *DraftMultipart) SetAuthor(val OptString)
- func (s *DraftMultipart) SetHideAttachments(val OptBool)
- func (s *DraftMultipart) SetText(val string)
- func (s *DraftMultipart) SetTitle(val string)
- type HeaderAuth
- type HeaderToken
- type ID
- type Note
- func (s *Note) Decode(d *jx.Decoder) error
- func (s *Note) Encode(e *jx.Encoder)
- func (s *Note) GetID() ID
- func (s *Note) GetPublicURL() string
- func (s *Note) MarshalJSON() ([]byte, error)
- func (s *Note) SetID(val ID)
- func (s *Note) SetPublicURL(val string)
- func (s *Note) UnmarshalJSON(data []byte) error
- func (s *Note) Validate() error
- type OptBool
- type OptString
- type Option
- type QueryAuth
- type SecuritySource
- type UpdateNoteNoContent
- type UpdateNoteParams
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client implements OAS client.
func NewClient ¶
func NewClient(serverURL string, sec SecuritySource, opts ...ClientOption) (*Client, error)
NewClient initializes new Client defined by OAS.
Example ¶
package main import ( "context" "log" "github.com/reddec/api-notes/api/client" ) func main() { notes, err := client.NewClient("https://example.com", client.HeaderToken("deadbeaf")) if err != nil { // panic is used for illustration only panic("create notes client: " + err.Error()) } note, err := notes.CreateNote(context.Background(), &client.DraftMultipart{ Title: "Hello", Text: "## hello world\nThis is sample text", Author: client.NewOptString("demo"), }) if err != nil { panic("create note: " + err.Error()) } log.Println("Note ID:", note.ID) log.Println("Note URL:", note.PublicURL) }
Output:
func (*Client) CreateNote ¶
CreateNote invokes createNote operation.
Create new note from draft with (optional) attachments. Returns public URL and unique ID. Consumer should not make any assumptions about ID and treat it as arbitrary string with variable reasonable length. Attachments with name index.html will be ignored. Note can use relative reference to attachments as-is.
POST /notes
func (*Client) DeleteNote ¶
func (c *Client) DeleteNote(ctx context.Context, params DeleteNoteParams) error
DeleteNote invokes deleteNote operation.
Remove existent note and all attachments.
DELETE /note/{id}
func (*Client) UpdateNote ¶
func (c *Client) UpdateNote(ctx context.Context, request *DraftMultipart, params UpdateNoteParams) error
UpdateNote invokes updateNote operation.
Update existent note by ID. Old attachments may not be removed, but could be replaced.
PUT /note/{id}
type ClientOption ¶
type ClientOption interface {
// contains filtered or unexported methods
}
ClientOption is client config option.
func WithClient ¶
func WithClient(client ht.Client) ClientOption
WithClient specifies http client to use.
type DeleteNoteNoContent ¶
type DeleteNoteNoContent struct{}
DeleteNoteNoContent is response for DeleteNote operation.
type DeleteNoteParams ¶
type DeleteNoteParams struct { // Note ID. ID ID }
DeleteNoteParams is parameters of deleteNote operation.
type DraftMultipart ¶
type DraftMultipart struct { // Note title. Title string `json:"title"` // Note body. Text string `json:"text"` // Optional (and not verifiable) author of note. Author OptString `json:"author"` // Do not make list of attachments. HideAttachments OptBool `json:"hide_attachments"` // File attachment. Attachment []ht.MultipartFile `json:"attachment"` }
Ref: #/components/schemas/draft
func (*DraftMultipart) GetAttachment ¶
func (s *DraftMultipart) GetAttachment() []ht.MultipartFile
GetAttachment returns the value of Attachment.
func (*DraftMultipart) GetAuthor ¶
func (s *DraftMultipart) GetAuthor() OptString
GetAuthor returns the value of Author.
func (*DraftMultipart) GetHideAttachments ¶
func (s *DraftMultipart) GetHideAttachments() OptBool
GetHideAttachments returns the value of HideAttachments.
func (*DraftMultipart) GetText ¶
func (s *DraftMultipart) GetText() string
GetText returns the value of Text.
func (*DraftMultipart) GetTitle ¶
func (s *DraftMultipart) GetTitle() string
GetTitle returns the value of Title.
func (*DraftMultipart) SetAttachment ¶
func (s *DraftMultipart) SetAttachment(val []ht.MultipartFile)
SetAttachment sets the value of Attachment.
func (*DraftMultipart) SetAuthor ¶
func (s *DraftMultipart) SetAuthor(val OptString)
SetAuthor sets the value of Author.
func (*DraftMultipart) SetHideAttachments ¶
func (s *DraftMultipart) SetHideAttachments(val OptBool)
SetHideAttachments sets the value of HideAttachments.
func (*DraftMultipart) SetText ¶
func (s *DraftMultipart) SetText(val string)
SetText sets the value of Text.
func (*DraftMultipart) SetTitle ¶
func (s *DraftMultipart) SetTitle(val string)
SetTitle sets the value of Title.
type HeaderAuth ¶
type HeaderAuth struct {
APIKey string
}
func (*HeaderAuth) GetAPIKey ¶
func (s *HeaderAuth) GetAPIKey() string
GetAPIKey returns the value of APIKey.
func (*HeaderAuth) SetAPIKey ¶
func (s *HeaderAuth) SetAPIKey(val string)
SetAPIKey sets the value of APIKey.
type HeaderToken ¶ added in v0.2.1
type HeaderToken string
HeaderToken is header base authorization with pre-shared token.
func (HeaderToken) HeaderAuth ¶ added in v0.2.1
func (ta HeaderToken) HeaderAuth(_ context.Context, _ string) (HeaderAuth, error)
func (HeaderToken) QueryAuth ¶ added in v0.2.1
QueryAuth ignored and always returns ogenerrors.ErrSkipClientSecurity.
type ID ¶
type ID string
func (ID) MarshalJSON ¶
MarshalJSON implements stdjson.Marshaler.
func (*ID) UnmarshalJSON ¶
UnmarshalJSON implements stdjson.Unmarshaler.
type Note ¶
Ref: #/components/schemas/note
func (*Note) GetPublicURL ¶
GetPublicURL returns the value of PublicURL.
func (*Note) MarshalJSON ¶
MarshalJSON implements stdjson.Marshaler.
func (*Note) SetPublicURL ¶
SetPublicURL sets the value of PublicURL.
func (*Note) UnmarshalJSON ¶
UnmarshalJSON implements stdjson.Unmarshaler.
type OptBool ¶
OptBool is optional bool.
func NewOptBool ¶
NewOptBool returns new OptBool with value set to v.
type OptString ¶
OptString is optional string.
func NewOptString ¶
NewOptString returns new OptString with value set to v.
type Option ¶
type Option interface { ClientOption }
Option is config option.
func WithMeterProvider ¶
func WithMeterProvider(provider metric.MeterProvider) Option
WithMeterProvider specifies a meter provider to use for creating a meter.
If none is specified, the otel.GetMeterProvider() is used.
func WithTracerProvider ¶
func WithTracerProvider(provider trace.TracerProvider) Option
WithTracerProvider specifies a tracer provider to use for creating a tracer.
If none is specified, the global provider is used.
type QueryAuth ¶
type QueryAuth struct {
APIKey string
}
type SecuritySource ¶
type SecuritySource interface { // HeaderAuth provides HeaderAuth security value. HeaderAuth(ctx context.Context, operationName string) (HeaderAuth, error) // QueryAuth provides QueryAuth security value. QueryAuth(ctx context.Context, operationName string) (QueryAuth, error) }
SecuritySource is provider of security values (tokens, passwords, etc.).
type UpdateNoteNoContent ¶
type UpdateNoteNoContent struct{}
UpdateNoteNoContent is response for UpdateNote operation.
type UpdateNoteParams ¶
type UpdateNoteParams struct { // Note ID. ID ID }
UpdateNoteParams is parameters of updateNote operation.