client

package
v0.2.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 14, 2023 License: MIT Imports: 24 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func WithServerURL

func WithServerURL(ctx context.Context, u *url.URL) context.Context

WithServerURL sets context key to override server URL.

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

func (c *Client) CreateNote(ctx context.Context, request *DraftMultipart) (*Note, error)

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

func (ta HeaderToken) QueryAuth(_ context.Context, _ string) (QueryAuth, error)

QueryAuth ignored and always returns ogenerrors.ErrSkipClientSecurity.

type ID

type ID string

func (*ID) Decode

func (s *ID) Decode(d *jx.Decoder) error

Decode decodes ID from json.

func (ID) Encode

func (s ID) Encode(e *jx.Encoder)

Encode encodes ID as json.

func (ID) MarshalJSON

func (s ID) MarshalJSON() ([]byte, error)

MarshalJSON implements stdjson.Marshaler.

func (*ID) UnmarshalJSON

func (s *ID) UnmarshalJSON(data []byte) error

UnmarshalJSON implements stdjson.Unmarshaler.

func (ID) Validate

func (s ID) Validate() error

type Note

type Note struct {
	ID ID `json:"id"`
	// Public URL.
	PublicURL string `json:"public_url"`
}

Ref: #/components/schemas/note

func (*Note) Decode

func (s *Note) Decode(d *jx.Decoder) error

Decode decodes Note from json.

func (*Note) Encode

func (s *Note) Encode(e *jx.Encoder)

Encode implements json.Marshaler.

func (*Note) GetID

func (s *Note) GetID() ID

GetID returns the value of ID.

func (*Note) GetPublicURL

func (s *Note) GetPublicURL() string

GetPublicURL returns the value of PublicURL.

func (*Note) MarshalJSON

func (s *Note) MarshalJSON() ([]byte, error)

MarshalJSON implements stdjson.Marshaler.

func (*Note) SetID

func (s *Note) SetID(val ID)

SetID sets the value of ID.

func (*Note) SetPublicURL

func (s *Note) SetPublicURL(val string)

SetPublicURL sets the value of PublicURL.

func (*Note) UnmarshalJSON

func (s *Note) UnmarshalJSON(data []byte) error

UnmarshalJSON implements stdjson.Unmarshaler.

func (*Note) Validate

func (s *Note) Validate() error

type OptBool

type OptBool struct {
	Value bool
	Set   bool
}

OptBool is optional bool.

func NewOptBool

func NewOptBool(v bool) OptBool

NewOptBool returns new OptBool with value set to v.

func (OptBool) Get

func (o OptBool) Get() (v bool, ok bool)

Get returns value and boolean that denotes whether value was set.

func (OptBool) IsSet

func (o OptBool) IsSet() bool

IsSet returns true if OptBool was set.

func (OptBool) Or

func (o OptBool) Or(d bool) bool

Or returns value if set, or given parameter if does not.

func (*OptBool) Reset

func (o *OptBool) Reset()

Reset unsets value.

func (*OptBool) SetTo

func (o *OptBool) SetTo(v bool)

SetTo sets value to v.

type OptString

type OptString struct {
	Value string
	Set   bool
}

OptString is optional string.

func NewOptString

func NewOptString(v string) OptString

NewOptString returns new OptString with value set to v.

func (OptString) Get

func (o OptString) Get() (v string, ok bool)

Get returns value and boolean that denotes whether value was set.

func (OptString) IsSet

func (o OptString) IsSet() bool

IsSet returns true if OptString was set.

func (OptString) Or

func (o OptString) Or(d string) string

Or returns value if set, or given parameter if does not.

func (*OptString) Reset

func (o *OptString) Reset()

Reset unsets value.

func (*OptString) SetTo

func (o *OptString) SetTo(v string)

SetTo sets value 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
}

func (*QueryAuth) GetAPIKey

func (s *QueryAuth) GetAPIKey() string

GetAPIKey returns the value of APIKey.

func (*QueryAuth) SetAPIKey

func (s *QueryAuth) SetAPIKey(val string)

SetAPIKey sets the value of APIKey.

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL