service

package module
v0.0.0-...-5d963cc Latest Latest
Warning

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

Go to latest
Published: Jun 9, 2018 License: Apache-2.0 Imports: 6 Imported by: 0

README

Service

TXN2 Golang service libraries. Check out Go Microservices Boilerplate for examples and a refrence implementation.

Install
go get github.com/txn2/service

Ack

HTTP service acknowledgement structure.

The Ack data structure is used for providing a common wrapper around HTTP JSON api calls developed in go.

// Ack
type Ack struct {
	Version     int         `json:"ack_version"`
	Agent       string      `json:"agent"`
	Uuid        string      `json:"ack_uuid"`
	RequestUuid string      `json:"req_uuid"`
	DateTime    string      `json:"date_time"`
	Success     bool        `json:"success"`
	ServerCode  int         `json:"server_code"`
	Location    string      `json:"location"`
	PayloadType string      `json:"payload_type"`
	Payload     interface{} `json:"payload"`
}

Example JSON:

{
    "ack_version": 5,
    "agent": "",
    "ack_uuid": "f8b0d2ca-5a7c-48fd-ba26-5b53946d741c",
    "req_uuid": "",
    "date_time": "2018-06-05T10:36:38-07:00",
    "success": true,
    "server_code": 200,
    "location": "/",
    "payload_type": "Message",
    "payload": {
        "message": "service boilerplate"
    }
}
Use with gin-gonic web framework:
go get github.com/txn2/service/ginack

Example implementation:

import (
	"github.com/gin-gonic/gin"
	"github.com/txn2/service/ginack"
)

...
    // route handler
    func(c *gin.Context) {
        ack := ginack.Ack(c)
        ack.SetPayload(gin.H{"message":"service boilerplate"})
    
        // return
        c.JSON(ack.ServerCode, ack)
    }
...

Cassandra

See examples folder.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Cassandra

func Cassandra(cfg CassandraCfg) (*cas, error)

Cassandra produces a cassandra object with session

func CassandraFromCfg

func CassandraFromCfg(cfg Cfg) (*cas, error)

CassandraFromCfg takes a configuration map

func NewTokenGenerator

func NewTokenGenerator(cfg Cfg) (*tok, error)

NewTokenGenerator returns a configured tok used for generating tokens

Types

type Ack

type Ack struct {
	Version     int         `json:"ack_version"`
	Agent       string      `json:"agent"`
	Uuid        string      `json:"ack_uuid"`
	RequestUuid string      `json:"req_uuid"`
	DateTime    string      `json:"date_time"`
	Success     bool        `json:"success"`
	ServerCode  int         `json:"server_code"`
	Location    string      `json:"location"`
	PayloadType string      `json:"payload_type"`
	Payload     interface{} `json:"payload"`
	Duration    string      `json:"duration"`
	// contains filtered or unexported fields
}

Ack

func (*Ack) SetPayload

func (a *Ack) SetPayload(payload interface{})

SetPayload

func (*Ack) SetPayloadType

func (a *Ack) SetPayloadType(payloadType string)

SetPayloadType

func (*Ack) StartTimer

func (a *Ack) StartTimer()

StartTimer

type CasRows

type CasRows []map[string]interface{}

CasRows used for simple result sets not bound to a specific type

type CassandraCfg

type CassandraCfg struct {
	Cluster  []string `yaml:"cluster"`
	Keyspace string   `yaml:"keyspace"`
	Username string   `yaml:"username"`
	Password string   `yaml:"password"`
	NumConns int      `yaml:"numConns"`
}

Cassandra wrapper

type Cfg

type Cfg map[interface{}]interface{}

ServiceCfg used for all service wrappers requiring configuration such as cas and tok

type Pkg

type Pkg struct {
	Version   int                    `json:"pkg_version"`
	Uuid      string                 `json:"pkg_uuid"`
	PDateTime string                 `json:"pgk_date_time"`
	Client    map[string]interface{} `json:"client"`
}

Pkg

type TokenCfg

type TokenCfg struct {
	EncKey   string `yaml:"encKey"`
	ExpHours int    `yaml:"expHours"`
}

Directories

Path Synopsis
Package main is a boilerplate for JSON based microservices.
Package main is a boilerplate for JSON based microservices.

Jump to

Keyboard shortcuts

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