natsdb

package module
v0.0.0-...-bdbb5c7 Latest Latest
Warning

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

Go to latest
Published: Jun 12, 2018 License: MPL-2.0 Imports: 3 Imported by: 2

README

NatsDB

NatsDB is a nats layer on top of an entity, so you can interact with any model through your messaging system.

Build status

master: CircleCI Master

Installation

make deps
make install

Running Tests

make deps
go test

Contributing

Please read through our contributing guidelines. Included are directions for opening issues, coding standards, and notes on development.

Moreover, if your pull request contains patches or features, you must include relevant unit tests.

Versioning

For transparency into our release cycle and in striving to maintain backward compatibility, this project is maintained under the Semantic Versioning guidelines.

Code and documentation copyright since 2015 r3labs.io authors.

Code released under the Mozilla Public License Version 2.0.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// NotFound : Error message for not found errors
	NotFound = ErrorMessage{Message: "Not found", Code: "404"}
	// Unexpected : Error message for unexpected errors
	Unexpected = ErrorMessage{Message: "Unexpected error", Code: "500"}
)

Functions

This section is empty.

Types

type ErrorMessage

type ErrorMessage struct {
	Message string `json:"_error"`
	Code    string `json:"_code"`
}

ErrorMessage : Struct representing an error message

func (*ErrorMessage) Encoded

func (e *ErrorMessage) Encoded() []byte

Encoded : represent ErrorMessage as a json string

type Handler

type Handler struct {
	Nats                   *nats.Conn
	NewModel               func() Model
	NotFoundErrorMessage   []byte
	UnexpectedErrorMessage []byte
	DeletedMessage         []byte
}

Handler : this struct manages all nats connections and maps them to the injected entity

func (*Handler) Del

func (h *Handler) Del(msg *nats.Msg)

Del : Based on a json input with an id field will delete the client details for this id

func (*Handler) Fail

func (h *Handler) Fail(msg *nats.Msg)

Fail : It replies the nats message with a not found error

func (*Handler) Find

func (h *Handler) Find(msg *nats.Msg)

Find : Based on the fields of the input json it will search and return any entity matching these fields

func (*Handler) Get

func (h *Handler) Get(msg *nats.Msg)

Get : Based on a json input with an id field will return the client details for this id

func (*Handler) Set

func (h *Handler) Set(msg *nats.Msg)

Set : Based on a json input with an id field will update the client details for this id with all extra fields defined on the message

type Model

type Model interface {
	MapInput(body []byte)
	LoadFromInput(msg []byte) bool
	LoadFromInputOrFail(msg *nats.Msg, h *Handler) bool
	Update(body []byte) error
	Delete() error
	Save() error
	Find() []interface{}
	HasID() bool
}

Model : This is the interface you need to implement in order to inject a db manager to the Handler

Jump to

Keyboard shortcuts

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