kratos

package module
v1.1.2 Latest Latest
Warning

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

Go to latest
Published: Sep 26, 2023 License: MIT Imports: 33 Imported by: 2

README

Build Status GoDoc codeCov Go Report Card License Awesome Go Discord

Translate to: 简体中文

About Kratos

The name is inspired by the Greek-mythology-based game "God of War". It tells the adventures of Kratos becoming a god of war from a mortal and launching a god-killing slaughter.

Kratos is a microservice-oriented governance framework implemented by golang, which offers convenient capabilities to help you quickly build a bulletproof application from scratch, such as:

Kratos is accessible, powerful, and provides tools required for large, robust applications.

Learning Kratos

Kratos has the most extensive and thorough documentation and example library of all modern web application frameworks, making it a breeze to get started with the framework.

We also provide a modern template. This template should help reduce the work required to setup up modern projects.

Goals

Kratos boosts your productivity. With the integration of excellent resources and further support, programmers can get rid of most issues might encounter in the field of distributed systems and software engineering such that they are allowed to focus on the release of businesses only. Additionally, for each programmer, Kratos is also an ideal one learning warehouse for many aspects of microservices to enrich their experiences and skills.

Principles

  • Simple: Appropriate design with plain and easy code.
  • General: Cover the various utilities for business development.
  • Highly efficient: Speeding up the efficiency of businesses upgrading.
  • Stable: The base libs validated in the production environment have the characteristics of high testability, high coverage as well as high security and reliability.
  • Robust: Eliminating misusing through high quality of the base libs.
  • High-performance: Optimal performance excluding the optimization of hacking in case of unsafe
  • Expandability: Properly designed interfaces where you can expand utilities such as base libs to meet your further requirements.
  • Fault-tolerance: Designed against failure, enhance the understanding and exercising of SRE within Kratos to achieve more robustness.
  • Toolchain: Includes an extensive toolchain, such as the code generation of cache, the lint tool, and so forth.
Getting Started

Create a kratos playground through docker:

docker run -it --rm -p 8000:8000 --workdir /workspace golang
apt-get update && apt-get -y install protobuf-compiler
export GOPROXY=https://goproxy.io,direct
go install github.com/go-kratos/kratos/cmd/kratos/v2@latest && kratos upgrade
kratos new helloworld
cd helloworld/ && go mod tidy
kratos run

Use a browser to open and visit: http://localhost:8000/helloworld/kratos, The kratos program is running!

If you need more, please visit the kratos documentation.

Security Vulnerabilities

If you discover a security vulnerability within Kratos, please send an e-mail to tonybase via go-kratos@googlegroups.com. All security vulnerabilities will be promptly addressed.

Community Contributors

Thank you for considering contributing to the Kratos framework! The contribution guide can be found in the Kratos documentation.

License

The Kratos framework is open-sourced software licensed under the MIT license.

Acknowledgments

The following project had particular influence on kratos's design.

  • go-kit/kit is a programming toolkit for building microservices in go.
  • asim/go-micro a distributed systems development framework.
  • google/go-cloud is go cloud development kit.
  • zeromicro/go-zero is a web and rpc framework with lots of builtin engineering practices.
  • beego/beego is a web framework including RESTful APIs, web apps and backend services.

Documentation

Index

Constants

View Source
const Release = "v2.7.0"

Release is the current kratos version.

Variables

This section is empty.

Functions

func NewContextFromApp

func NewContextFromApp(ctx context.Context, s AppInfo) context.Context

NewContextFromApp returns a new Context that carries value.

Types

type App

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

App is an application components lifecycle manager.

func New

func New(opts ...Option) *App

New create an application lifecycle manager.

func (*App) Config

func (a *App) Config() config.Config

Config returns service config.

func (*App) Endpoint

func (a *App) Endpoint() []string

Endpoint returns endpoints.

func (*App) ID

func (a *App) ID() string

ID returns app instance id.

func (*App) Metadata

func (a *App) Metadata() map[string]string

Metadata returns service metadata.

func (*App) Name

func (a *App) Name() string

Name returns service name.

func (*App) Run

func (a *App) Run() error

Run executes all OnStart hooks registered with the application's Lifecycle.

func (*App) Stop

func (a *App) Stop() (err error)

Stop gracefully stops the application.

func (*App) Version

func (a *App) Version() string

Version returns app version.

type AppInfo

type AppInfo interface {
	ID() string
	Name() string
	Version() string
	Metadata() map[string]string
	Endpoint() []string
	Config() config.Config
}

AppInfo is application context value.

func GetAppFromContext

func GetAppFromContext(ctx context.Context) (s AppInfo, ok bool)

GetAppFromContext returns the Transport value stored in ctx, if any.

type Context

type Context interface {
	Logger() *log.Helper
	DB(name ...string) *gorm.DB
	Go(runner pool.Runner) error
	Cert(name string) []byte
	Email() (email.Sender, error)
	ClientIP() string
	Captcha() captcha.Captcha
	JWT() jwt.Jwt
	Authentication() authentication.Authentication

	ID() string
	Name() string
	Version() string
	Metadata() map[string]string
	Config() config.Config
	Endpoint() []string

	Deadline() (deadline time.Time, ok bool)
	Done() <-chan struct{}
	Err() error
	Value(key any) interface{}
}

func MustContext

func MustContext(c context.Context) Context

MustContext returns the Transport value stored in ctx, if any.

type LogField

type LogField map[string]interface{}

type Option

type Option func(o *options)

Option is an application option.

func AfterStart

func AfterStart(fn func(context.Context) error) Option

AfterStart run funcs after app starts

func AfterStop

func AfterStop(fn func(context.Context) error) Option

AfterStop run funcs after app stops

func BeforeStart

func BeforeStart(fn func(context.Context) error) Option

BeforeStart run funcs before app starts

func BeforeStop

func BeforeStop(fn func(context.Context) error) Option

BeforeStop run funcs before app stops

func Config

func Config(source config.Source) Option

Config with service config.

func Endpoint

func Endpoint(endpoints ...*url.URL) Option

Endpoint with service endpoint.

func ID

func ID(id string) Option

ID with service id.

func LoggerWith

func LoggerWith(fields LogField) Option

LoggerWith with service logger with field.

func Metadata

func Metadata(md map[string]string) Option

Metadata with service metadata.

func Name

func Name(name string) Option

Name with service name.

func Registrar

func Registrar(r registry.Registrar) Option

Registrar with service registry.

func RegistrarServer

func RegistrarServer(fn registrarServerFn) Option

RegistrarServer with service register server.

func RegistrarTimeout

func RegistrarTimeout(t time.Duration) Option

RegistrarTimeout with registrar timeout.

func Server

func Server(srv ...transport.Server) Option

Server with transport servers.

func Signal

func Signal(sigs ...os.Signal) Option

Signal with exit signals.

func StopTimeout

func StopTimeout(t time.Duration) Option

StopTimeout with app stop timeout.

func Version

func Version(version string) Option

Version with service version.

Jump to

Keyboard shortcuts

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