Documentation ¶
Overview ¶
Package client provides an http client of uqrate services.
Package client provides an HTTP client of Uqrate services.
Index ¶
- Constants
- func Example(env *Env) error
- func GhostPrint(format string, args ...interface{})
- type ApiKey
- type Build
- type CSRF
- type Channel
- type Client
- type Env
- func (env *Env) Get(url, cType string) *Response
- func (env *Env) GetCache(key string) []byte
- func (env *Env) GetCacheJSON(key string, ptr interface{})
- func (env *Env) PatchKey(cid string, arg ...string) *Response
- func (env *Env) PostByKey(key, url string, data interface{}) *Response
- func (env *Env) PostByTkn(tkn, url string, data interface{}) *Response
- func (env *Env) PrettyPrint() error
- func (env *Env) PutByKey(key, url string, data interface{}) *Response
- func (env *Env) PutByTkn(tkn, url string, data interface{}) *Response
- func (env *Env) SetCache(key, data string) error
- func (env *Env) Token(args ...string) *Response
- func (env *Env) Trace(endpt, cType string) *Response
- func (env *Env) UpsertMsgByKey(msg *Message, key string) *Response
- func (env *Env) UpsertMsgByTkn(msg *Message, args ...string) *Response
- type Error
- type JWT
- type Message
- type Response
- type Service
- type UpsertStatus
- type User
Constants ¶
const ( REQUEST = iota + 1 CLIENT )
Levels
REQUEST is sans client-added latencies. CLIENT includes client-added latencies.
const ( MODE_JSON = 1 MODE_STRUCT = 2 )
Mode
const ( BASE_AOA = "/aoa/v1" BASE_API = "/api/v1" )
Service base
const ( JSON = "application/json" HTML = "text/html" )
Content type for HTTP request header : "Accept: ..."
const (
CacheKeyTknPrefix = "tkn."
)
const ENDPT_UPSERT_KEY = "/key/m/upsert"
const ENDPT_UPSERT_TKN = "/m/upsert"
const KEY_ENDPT = "/c/key/"
const MaxUserDisplay = 30
const TKN_ENDPT = "/a/token"
Variables ¶
This section is empty.
Functions ¶
func GhostPrint ¶ added in v0.3.9
func GhostPrint(format string, args ...interface{})
GhostPrint(..) prints args per format, e.g., "want: %s\nhave: %s\n", to os.Stderr.
Types ¶
type ApiKey ¶ added in v0.3.9
type ApiKey struct { XID string `db:"xid" json:"xid,omitempty"` Scope int `db:"scope" json:"scope,omitempty"` Name string `db:"key_name" json:"key_name,omitempty"` Hash []byte `db:"key_hash" json:"-"` DateCreate time.Time `db:"date_create" json:"date_create"` DateUpdate time.Time `db:"date_update" json:"date_update,omitempty"` Rotations int `db:"rotations" json:"rotations,omitempty"` Key string `db:"-" json:"key,omitempty"` Value string `db:"-" json:"key_value,omitempty"` Error string `db:"-" json:"error,omitempty"` // All possible fields of all scopes (models), else handle per model OwnerID string `db:"owner_id" json:"owner_id,omitempty"` // channels.owner_id ChnID string `db:"chn_id" json:"chn_id,omitempty"` // channels.chn_id ChnSlug string `db:"chn_slug" json:"chn_slug,omitempty"` // channels.slug HostURL string `db:"host_url" json:"host_url,omitempty"` // channels.host_url }
type Build ¶ added in v0.3.14
type Build struct { Desc string `json:"desc,omitempty"` Maker string `json:"maker,omitempty"` SVN string `json:"svn,omitempty"` Version string `json:"version,omitempty"` Built string `json:"built,omitempty"` Year string `json:"year,omitempty"` }
Build contains application build info.
type Channel ¶
type Channel struct { ID string `json:"chn_id,omitempty"` // Channel.ID // host : <hostname> : domain // host url : <scheme>://<hostname>:<port> : url HostURL string `json:"host_url,omitempty"` // Channel.HostURL Slug string `json:"slug,omitempty"` // Channel.Slug OwnerID string `json:"owner_id,omitempty"` // Channel.OwnerID (UUID v4) // Thread-root message (long-form) ThreadID string `json:"thread_id,omitempty"` // Message.ID (UUID v5) Title string `json:"title,omitempty"` About string `json:"about,omitempty"` Tags []string `json:"tags,omitempty"` }
Channel regards that to which a message is upserted; at store of Service host.
type Client ¶
type Client struct { User string `json:"user,omitempty"` Pass string `json:"pass,omitempty"` Token string `json:"token,omitempty"` Key string `json:"key,omitempty"` UserAgent string `json:"user_agent,omitempty"` Timeout time.Duration `json:"timeout,omitempty"` TraceLevel int `json:"trace_level,omitempty"` TraceDump bool `json:"trace_dump,omitempty"` TraceFpath string `json:"trace_fpath,omitempty"` }
Client contains all request parameters.
type Env ¶
type Env struct { Logger *log.Logger Args conf.Args `json:"args,omitempty"` NS string `json:"ns,omitempty"` Build `json:"build"` Assets string `json:"assets,omitempty"` Cache string `json:"cache,omitempty"` SitesPass string `json:"sites_pass,omitempty"` SitesListCSV string `json:"sites_list_csv,omitempty"` SitesListJSON string `json:"sites_list_json,omitempty"` Client `json:"client,omitempty"` Service `json:"service,omitempty"` Channel `json:"channel,omitempty"` }
Env is the receiver of all (exported) client functions, and contains all parameters defining the client environment.
func (*Env) Get ¶ added in v0.3.9
Get returns the *Response of a GET.
cType : HTML or JSON (default).
func (*Env) GetCacheJSON ¶ added in v0.3.9
GetCacheJSON reads key file of Env.Cache folder into struct of pointer.
func (*Env) PostByKey ¶ added in v0.3.9
PostByKey makes POST request with header: `X-API-KEY: <KEY>`
func (*Env) PostByTkn ¶ added in v0.3.9
PostByTkn makes a POST request with header: `Authorization: Bearer <TKN>`
func (*Env) PrettyPrint ¶
func (*Env) PutByTkn ¶ added in v0.3.13
PutByTkn makes a PUT request with header: `Authorization: Bearer <TKN>`
func (*Env) Token ¶
Token retrieves an access token (JWT) per Basic Auth request.
Defaults: user (args[0]): Env.Client.User, pass (args[1]): Env.Client.Pass
func (*Env) Trace ¶
Trace hits the declared endpoint (any) with a GET request, prints response-timing info to os.Stderr, and returns response body else info. Dumps body to file instead if both TraceDump flag and TraceFpath set (see Env.Client). https://github.com/imroc/req#Debugging
func (*Env) UpsertMsgByKey ¶ added in v0.3.9
UpsertMsgByKey performs a POST request to Uqrate's API service endpoint for upserting a long-form Message (msg) of an externally-hosted Channel. Authorization to that protected endpoint is by ApiKey (key), scoped to its target channel, sent as value of X-API-KEY header.
Defaults: key: env.GetCacheJSON(..) @ "${APP_CACHE}/keys/key." + msg.ChnID + ".json"
func (*Env) UpsertMsgByTkn ¶ added in v0.3.9
UpsertMsgByTkn performs a POST request to Uqrate's API service endpoint for upserting a long-form Message (msg) of an externally-hosted Channel.Slug (slug) using bearer-token (token) authorization.
Defaults: token (args[0]): env.GetCache(client.CacheKeyTknPrefix + env.Client.User) @ ${APP_CACHE}/tkn.${APP_CLIENT_USER} slug (args[1]): env.Channel.Slug @ ${APP_CHANNEL_SLUG}
type Error ¶ added in v0.3.9
type Error struct { Error string `json:"error,omitempty"` Fields []string `json:"fields,omitempty"` }
TODO : Mod to this; See uqrate error response; has this detailed morphadite error response which gets lost in decode.
type Message ¶
type Message struct { ID string `json:"msg_id,omitempty"` //... Key NOT EXIST @ Uqrate struct ChnID string `json:"chn_id,omitempty"` Title string `json:"title,omitempty"` Summary string `json:"summary,omitempty"` Body string `json:"body,omitempty"` Cats []string `json:"cats,omitempty"` Tags []string `json:"tags,omitempty"` URI string `json:"uri,omitempty"` // DateCreate time.Time `db:"date_create" json:"date_create,omitempty"` //... Not exist @ uqrate mirror DateUpdate time.Time `json:"date_update,omitempty"` }
Message contains the payload to be decoded into a message.UpdateMessage by Uqrate API.
type Response ¶
type Response struct { Body string `json:"body,omitempty"` Code int `json:"code,omitempty"` Error string `json:"error,omitempty"` }
Response is the return of all (exported) client function calls.
type Service ¶
type Service struct { // <hostname> (domain) Host string `json:"host,omitempty"` // <scheme>://<hostname>:<port> BaseURL string `json:"base_url,omitempty"` // <scheme>://<hostname>:<port>/<service>/<version> BaseAOA string `json:"base_aoa,omitempty"` BaseAPI string `json:"base_api,omitempty"` BasePWA string `json:"base_pwa,omitempty"` }
Service regards that requested by Client; that servicing Message(s) of Channel(s).
type UpsertStatus ¶
type UpsertStatus struct { //IDx int `db:"idx" json:"idx"` // Required @ SELECT, e.g., @ Retrieve() ID string `db:"msg_id" json:"msg_id"` Mode int `db:"mode" json:"mode"` // 201, 204, 404 Error string `db:"-" json:"error,omitempty"` }
UpsertStatus must fit message.UpsertStatus
type User ¶ added in v0.3.13
type User struct { ID string `json:"user_id,omitempty"` // Not contained in service user.UpdateUser Display string `json:"display,omitempty"` About string `json:"about,omitempty"` Avatar string `json:"avatar,omitempty"` Banner string `json:"banner,omitempty"` }
User regards that of the service account, channel owner, hosting site, and credited author.
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
Package wordpress handles REST APIs of WordPress and Uqrate to process []wordpress.Post into []client.Message for upsert at Uqrate.
|
Package wordpress handles REST APIs of WordPress and Uqrate to process []wordpress.Post into []client.Message for upsert at Uqrate. |