_go

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: May 31, 2018 License: MIT Imports: 5 Imported by: 0

README

Go Client GoDoc

typebook client for Go.

Installation

$ go get github.com/cyberagent/typebook/client/go

Getting Started

To import this library,

import typebook "github.com/cyberagent/typebook/client/go"

Then instantiate a client as follows,

client := typebook.NewClient("localhost:8888")

After that, you can interact with typebook using the client!

client.CreateSubject("payment", "personal payment data")
schemaId, err := client.RegisterSchema("payment", `
    {
        "namespace": "jp.co.cyberagent.typebook.example",
        "type": "record",
        "name": "Payment",
        "fields": [
            {
                "name": "id",
                "type": "int"
            },
            {
                "name": "name",
                "type": "string"
            },
            {
                "name": "amount",
                "type": "double"
            },
            {
                "name": "time",
                "type": "long"
            }
        ]
    }`)

Configure client behavior

This client is thin wrapper of gorequest. Please consult gorequest documentation.

API

See GoDoc reference for detailed API documentation.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	DisableTransportSwap = false
)

Functions

This section is empty.

Types

type Client

type Client struct {
	*gorequest.SuperAgent
	// contains filtered or unexported fields
}

func NewClient

func NewClient(endpoint string) *Client

NewClient create and instantiate a new Client object which can interact with typebook server at the designated endpoint. endpoint should be in the form of `host:port`. Client instances should create for each goroutine to send multiple requests concurrently.

func (Client) CheckCompatibilityWithLatest

func (sc Client) CheckCompatibilityWithLatest(subject, definition string) (*model.Compatibility, *model.Error)

CheckCompatibilityWithLatest issues POST /compatibility/subjects/(subject string)/versions/latest with a schema definition in its body to a typebook server. It will check if the posted schema is compatible with the latest one under the given subject. This method returns model.Compatibility on success otherwise non-nil model.Error is returned.

func (Client) CheckCompatibilityWithMajorVersion

func (sc Client) CheckCompatibilityWithMajorVersion(subject string, majorVersion int, definition string) (*model.Compatibility, *model.Error)

CheckCompatibilityWithMajorVersion issues POST /compatibility/subjects/(subject string)/versions/v(majorVersion int) with a schema definition in its body to a typebook server. It will check if the posted schema is compatible with the latest one that has the designated major version under the given subject. This method returns model.Compatibility on success otherwise non-nil model.Error is returned.

func (Client) CheckCompatibilityWithSemVer

func (sc Client) CheckCompatibilityWithSemVer(subject string, semver model.SemVer, definition string) (*model.Compatibility, *model.Error)

CheckCompatibilityWithSemVer issues POST /compatibility/subjects/(subject string)/versions/(semver string) with a schema definition in its body to a typebook server. It will check if the posted schema is compatible with the one that has the designated semver under the given subject. This method returns model.Compatibility on success otherwise non-nil model.Error is returned.

func (Client) CreateSubject

func (sc Client) CreateSubject(name, description string) (int64, *model.Error)

CreateSubject issues a POST /subjects/(subject string) request with description in its body to a typebook server. It will create a new subject with given name and description. This method returns 0 for success otherwise returns non-nil model.Error.

func (Client) DeleteConfig

func (cc Client) DeleteConfig(subject string) (int64, *model.Error)

DeleteConfig issues a DELETE /config/(subject string) request to a typebook server. It will delete a whole config belongs to a subject with the given name. This method returns the number of deleted rows in the backend database or returns non-nil model.Error on failure.

func (Client) DeleteProperty

func (cc Client) DeleteProperty(subject, property string) (int64, *model.Error)

DeleteProperty issues a DELETE /config/(subject string)/properties/(property string) request to a typebook server. It will delete a specific property of config belongs to a subject with the given name. This method returns the number of deleted rows in the backend database so normally it is 1. Otherwise non-nil model.Error is returned.

func (Client) DeleteSubject

func (sc Client) DeleteSubject(name string) (int64, *model.Error)

DeleteSubject issues a DELETE /subjects/(subject string) to a typebook server. It will delete a subject which has the given name. This method returns the number of deleted rows in the backend database so normally it is 1 for success. Otherwise non-nil model.Error is returned

func (Client) GetConfig

func (cc Client) GetConfig(subject string) (*model.Config, *model.Error)

GetConfig issues a GET /config/(subject string) request to a typebook server. It will retrieve a whole config belongs to a subject with the given name. If it fails, non-nil model.Error is returned.

func (Client) GetLatestSchema

func (sc Client) GetLatestSchema(subject string) (*model.Schema, *model.Error)

GetLatestSchema issues a GET /subjects/(subject string)/versions/latest request to a typebook server. It will retrieve the latest schema under the given subject. This method returns model.Schema on success otherwise non-nil model.Error is returned.

func (Client) GetProperty

func (cc Client) GetProperty(subject, property string) (string, *model.Error)

GetProperty issues a GET /config/(subject string)/properties/(property string) request to a typebook server. It will retrieve a specific property of config belongs to a subject with the given name. If it fails, non-nil model.Error is returned.

func (Client) GetSchemaById

func (sc Client) GetSchemaById(id int64) (*model.Schema, *model.Error)

GetSchemaById issue a GET /schemas/ids/(id int64) request to a typebook server. It will retrieve the schema that matches the given id. This method returns model.Schema on success, otherwise non-nil model.Error is returned.

func (Client) GetSchemaByMajorVersion

func (sc Client) GetSchemaByMajorVersion(subject string, majorVersion int) (*model.Schema, *model.Error)

GetSchemaByMajorVersion issues a GET /subjects/(subject string)/versions/v(majorVersion int) request to a typebook server. It will retrieve a latest schema that has designated major version under the given subject. This method returns model.Schema on success otherwise non-nil model.Error is returned.

func (Client) GetSchemaBySemVer

func (sc Client) GetSchemaBySemVer(subject string, semver model.SemVer) (*model.Schema, *model.Error)

GetSchemaBySemVer issues a GET /subjects/(subject string)/versions/(semver string) request to a typebook server. It will retrieve a schema that has designated semver under the given subject. This method returns model.Schema on success otherwise non-nil model.Error is returned.

func (Client) GetSubject

func (sc Client) GetSubject(name string) (*model.Subject, *model.Error)

GetSubject issues a GET /subjects/(subject string) request to a typebook server. It will retrieve a subject which has the given name. If it fails, non-nil model.Error is returned.

func (Client) ListSubjects

func (sc Client) ListSubjects() ([]string, *model.Error)

ListSubjects issues a GET /subjects request to a typebook server. It will retrieve a list of names of existing subjects. If it fails, non-nil model.Error is returned.

func (Client) ListVersions

func (sc Client) ListVersions(subject string) ([]model.SemVer, *model.Error)

ListVersions issues a GET /subjects/(subject string)/versions request to a typebook server. It retrieves all existing versions under the given subject. This method returns a list of model.SemVer on success, otherwise non-nil model.Error is returned.

func (Client) LookupAllSchemas

func (sc Client) LookupAllSchemas(subject, definition string) ([]model.Schema, *model.Error)

LookupAllSchemas issues a POST /subjects/(subject string)/schema/lookupAll request with a schema definition to lookup in its body to a typebook server. It will lookup all schemas whose definition conforms to the given one within the given subject. If multiple schemas are found, all schemas are returned. This method returns non-nil model.Error on failure.

func (Client) LookupSchema

func (sc Client) LookupSchema(subject, definition string) (*model.Schema, *model.Error)

LookupSchema issues a POST /subjects/(subject string)/schema/lookup request with a schema definition to lookup in its body to a typebook server. It will lookup a schema by its definition within the given subject. If multiple schemas are found, the latest one is chosen. This method returns model.Schema whose definition conforms to the given one if found otherwise it returns non-nil model.Error.

func (Client) RegisterSchema

func (sc Client) RegisterSchema(subject, definition string) (*model.SchemaId, *model.Error)

RegisterSchema issues a POST /subjects/(subject string)/versions request with a schema definition in its body to a typebook server. It will register a new schema under the given subject according to the given definition. This method returns model.SchemaId that represents id for the created schema on success, otherwise non-nil model.Error is returned.

func (Client) SetConfig

func (cc Client) SetConfig(subject string, config model.Config) (int64, *model.Error)

SetConfig issue a PUT /config/(subject string) request with config json in its body to a typebook server. It will create or update a whole config of the subject with the given name. This method returns the number of updated rows in the backend database otherwise non-nil model.Error is returned on failure.

func (Client) SetProperty

func (cc Client) SetProperty(subject, name, value string) (int64, *model.Error)

SetConfig issues a PUT /config/(subject string)/properties/(property string) request with its value in its body to a typebook server. It will create or update a specific property of config of a subject which has the given name. This method returns the number of updated rows so normally it is 1 for success, otherwise non-nil model.Error is returned.

func (Client) UpdateDescription

func (sc Client) UpdateDescription(name, description string) (int64, *model.Error)

UpdateDescription issues a PUT /subjects/(subject string) request with new description in its body to a typebook server. It will update a description of a subject which has the given name. This method returns the number of updated rows in the backend database so normally it is 1 for success. Otherwise non-nil model.Error is returned.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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