bone

package module
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Aug 16, 2022 License: MIT Imports: 12 Imported by: 13

README

Bone

Go Go Report Card MIT License codecov GoDoc

🦴 Non-intrusive Go micro-service framework to combine modules organically, base on go-kit.

Installation

$ go get -u github.com/mingslife/bone

Documentation

Go Packages

Quick start

package main

import "github.com/mingslife/bone"

func main() {
	options := bone.DefaultApplicationOptions()
	application := bone.NewApplication(options)
	// application.Use(...components)
	application.Run() // Listen on 127.0.0.1:8080
}

Example

bone-example

License

© 2022 Ming

Released under the MIT License

Documentation

Overview

Package bone is a Non-intrusive Go micro-service framework, to combine modules organically, base on go-kit.

Index

Constants

This section is empty.

Variables

View Source
var (
	// NewServer is shortcut of go-kit's http.NewServer.
	// NewServer constructs a new server, which implements http.Handler and wraps
	// the provided endpoint.
	NewServer = http.NewServer
	// EncodeJSONResquest is shortcut of go-kit's http.EncodeJSONRequest.
	// EncodeJSONRequest is an EncodeRequestFunc that serializes the request as a
	// JSON object to the Request body. Many JSON-over-HTTP services can use it as
	// a sensible default. If the request implements Headerer, the provided headers
	// will be applied to the request.
	EncodeJSONRequest = http.EncodeJSONRequest
	// EncodeXMLRequest is shortcut of go-kit's http.EncodeXMLRequest.
	// EncodeXMLRequest is an EncodeRequestFunc that serializes the request as a
	// XML object to the Request body. If the request implements Headerer,
	// the provided headers will be applied to the request.
	EncodeXMLRequest = http.EncodeXMLRequest
	// EncodeJSONResponse is shortcut of go-kit's http.EncodeJSONResponse.
	// EncodeJSONResponse is a EncodeResponseFunc that serializes the response as a
	// JSON object to the ResponseWriter. Many JSON-over-HTTP services can use it as
	// a sensible default. If the response implements Headerer, the provided headers
	// will be applied to the response. If the response implements StatusCoder, the
	// provided StatusCode will be used instead of 200.
	EncodeJSONResponse = http.EncodeJSONResponse
)

Functions

This section is empty.

Types

type Application

type Application struct {
	// contains filtered or unexported fields
}

Application defines the struct of Bone Application.

func NewApplication

func NewApplication(options *ApplicationOptions) *Application

NewApplication returns the instance of Bone Application.

func (*Application) Provide added in v0.0.5

func (app *Application) Provide(obj *inject.Object) error

Provide is a low-level API to provide *inject.Object to inject Bone Application. Do NOT use it except must to.

func (*Application) Run

func (app *Application) Run()

Run starts up the Bone Application.

func (*Application) Use

func (app *Application) Use(components ...Component)

Use injects the components to the Bone Application, combines other component into a interconnected system.

type ApplicationOptions

type ApplicationOptions struct {
	// Basic part
	Debug bool

	// HTTP part
	HttpEnable bool
	HttpHost   string
	HttpPort   int

	// gRPC part
	GrpcEnable bool
	GrpcHost   string
	GrpcPort   int
}

ApplicationOptions represents the options to create Bone Application instance.

func DefaultApplicationOptions

func DefaultApplicationOptions() *ApplicationOptions

DefaultApplicationOptions returns the default options to create Bone Application instance. Enable HTTP Server and disable gRPC Server by default.

type Component

type Component interface {
	Name() string
	Init() error
	Register() error
	Unregister() error
}

Component defines the common methods

type Controller

type Controller interface {
	// Register should be used to registering handlers.
	Register() error
}

Controller is a special component, which should be used for the controller's definition.

type Endpoint

type Endpoint interface {
}

Endpoint is a special component, which should be used for the endpoint's definition.

type Handler

type Handler func(ctx context.Context, req any) (rsp any, err error)

Handler defines how to handle a http request, should have decoding part and proccessing part at the same time.

type Logger

type Logger interface {
	Component

	// WithContext returns Logger, which has its own context, convenient for
	// tracking.
	WithContext(ctx context.Context) Logger
	// Debug logs to the DEBUG log.
	Debug(msg any, extra ...map[string]any)
	// Info logs to the INFO log.
	Info(msg any, extra ...map[string]any)
	// Warn logs to the WARN log.
	Warn(msg any, extra ...map[string]any)
	// Error logs to the Error log.
	Error(msg any, extra ...map[string]any)
	// Panic logs to the PANIC log. And application should panic, which is
	// recoverable, after calling this method.
	Panic(msg any, extra ...map[string]any)
	// Fatal logs to the FATAL log. And application should fatal, which is NOT
	// recoverable, after calling this method.
	Fatal(msg any, extra ...map[string]any)
}

Logger defines the common log methods.

type Model

type Model interface {
}

Model is a special component, which should be used for the model's definition.

type Module

type Module interface {
	Component
}

Module is a special component, which should be used for the module's definition.

type Repo

type Repo interface {
}

Repo is a special component, which should be used for the repository's definition.

type Router

type Router struct {
	*mux.Router
}

Router is a wrapper of *mux.Router.

func NewRouter

func NewRouter() *Router

NewRouter returns a Router instance of Bone Application.

type Service

type Service interface {
}

Service is a special component, which should be used for the service's definition.

type Transport

type Transport interface {
	// Register should be used to registering endpoints.
	Register() error
}

Transport is a special component, which should be used for the transport's definition.

Jump to

Keyboard shortcuts

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