fns

package module
v0.13.12 Latest Latest
Warning

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

Go to latest
Published: Oct 15, 2022 License: Apache-2.0 Imports: 23 Imported by: 8

README

Fns

简体中文


Fn services for Golang. Simplify the development process by using standardized development scheme. Every thing is service.

Features

  • Applicable to enterprise projects
    • Standardization
    • Environmental configuration
    • Rapid development by code generations
    • Built in authorizations service (schema is customizable)
    • Built in RBAC permission service
    • Built in metric service (schema is customizable)
    • Built in tracing service (schema is customizable)
    • Traceable and searchable error schema
    • Searchable log content schema
  • Code generations
    • Service of fn
    • Proxy of fn
    • Open api documents
    • Request argument validation
    • Authorizations validation
    • Permissions validation
  • High concurrency
    • Goroutines pool
    • Fasthttp as default http server (Http3 is optionally)
    • Request Barrier (Multiple identical requests will only process the first one, and others will share the results of the first one)
  • TLS
    • Standard
    • SSC (Auto generate cert and key by self sign ca, it is useful for building http3 based cluster)
    • ACMEs (Easy to use and supports auto-renew)
  • Cluster
    • Designated members
    • DOCKER SWARM (Auto find members by container label)
    • KUBERNETES (Auto find members by pod label)
  • Databases
    • SQL
      • Serviceability (Internal service)
      • Distributed SQL transaction (Non-intrusive and all databases are supported)
      • Postgres ORM (High performance)
      • Mysql ORM (To be tested)
      • GraphQL to SQL
    • Redis (Internal service)
    • Dgraph
  • Message queue
    • RabbitMQ
    • Kafka
    • Nats.IO
  • DDD
  • Extra listeners
    • MQTT
  • Third party integration
    • Oauth
    • Payments
    • SMS
    • Notifications

Quickstart

Create project

First: install fnc commander.

go install github.com/aacfactory/fnc@latest

Second: use fnc create a fns project.

mkdir {your project path}
cd {your project path}
fnc create 

Third: look main.go, config, modules to understand project structure.

Happy coding. Read usage for more.

Read openapi document

Setup swagger-ui, then open it.

docker run -d --rm --name swagger-ui \
 -p 80:8080 \
 -e SWAGGER_JSON_URL=http://ip:port/documents/oas \ 
 swaggerapi/swagger-ui 
Send request to fn
curl -H "Content-Type: application/json" -X POST -d '{}' http://ip:port/service/fn

Environmental configuration

Use FNS-ACTIVE environment to control which configuration to be merged into default configuration and used. The environment value could be local, dev, qa, and prod. Read configuration for more.

Cluster

Fns use Gossip-like schema to manage a cluster. Just turn on the cluster mode in project, then the endpoints of fn service will be auto registered and discovered, there is no difference of coding between cluster mode and standalone mode, so it is very easy to use. Read cluster for more.

Benchmark

CPU: AMD 3950X;
MEM: 64G;
RPS: 118850.991763/s;


          /\      |‾‾| /‾‾/   /‾‾/
     /\  /  \     |  |/  /   /  /
    /  \/    \    |     (   /   ‾‾\
   /          \   |  |\  \ |  (‾)  |
  / __________ \  |__| \__\ \_____/ .io

  execution: local
     script: ./test.js
     output: -

  scenarios: (100.00%) 1 scenario, 50 max VUs, 1m0s max duration (incl. graceful stop):
           * default: 50 looping VUs for 30s (gracefulStop: 30s)


running (0m30.0s), 00/50 VUs, 3565697 complete and 0 interrupted iterations
default ✓ [======================================] 50 VUs  30s

     ✓ status was 200

     checks.........................: 100.00% ✓ 3565697       ✗ 0
     data_received..................: 564 MB  19 MB/s
     data_sent......................: 521 MB  17 MB/s
     http_req_blocked...............: avg=1.58µs   min=0s med=0s   max=5.57ms   p(90)=0s      p(95)=0s
     http_req_connecting............: avg=24ns     min=0s med=0s   max=2.31ms   p(90)=0s      p(95)=0s
     http_req_duration..............: avg=261.31µs min=0s med=0s   max=12.92ms  p(90)=844.7µs p(95)=1ms
       { expected_response:true }...: avg=261.31µs min=0s med=0s   max=12.92ms  p(90)=844.7µs p(95)=1ms
     http_req_failed................: 0.00%   ✓ 0             ✗ 3565697
     http_req_receiving.............: avg=26.91µs  min=0s med=0s   max=8.65ms   p(90)=0s      p(95)=29.3µs
     http_req_sending...............: avg=10.53µs  min=0s med=0s   max=7.7ms    p(90)=0s      p(95)=0s
     http_req_tls_handshaking.......: avg=0s       min=0s med=0s   max=0s       p(90)=0s      p(95)=0s
     http_req_waiting...............: avg=223.86µs min=0s med=0s   max=12.43ms  p(90)=641.9µs p(95)=1ms
     http_reqs......................: 3565697 118850.991763/s
     iteration_duration.............: avg=412.23µs min=0s med=92µs max=118.81ms p(90)=1ms     p(95)=1ms
     iterations.....................: 3565697 118850.991763/s
     vus............................: 50      min=50          max=50
     vus_max........................: 50      min=50          max=50

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConfigActiveFromENV added in v0.1.1

func ConfigActiveFromENV(key string) (active string)

Types

type Application

type Application interface {
	Log() (log logs.Logger)
	Deploy(service ...service.Service) (err error)
	Run() (err error)
	RunWithHooks(ctx context.Context, hook ...Hook) (err error)
	Execute(ctx context.Context, serviceName string, fn string, argument interface{}) (result interface{}, err errors.CodeError)
	Sync() (err error)
}

func New

func New(options ...Option) (app Application)

type Hook

type Hook interface {
	Name() (name string)
	Build(options *HookOptions) (err error)
	Handle(ctx context.Context) (err error)
}

type HookOptions added in v0.13.11

type HookOptions struct {
	Log    logs.Logger
	Config configures.Config
}

type Option

type Option func(*Options) error

func Barrier added in v0.12.0

func Barrier(barrier service.Barrier) Option

func ClusterClientBuilder added in v0.12.0

func ClusterClientBuilder(builder cluster.ClientBuilder) Option

func ConfigRetriever

func ConfigRetriever(path string, format string, active string, prefix string, splitter byte) Option

func ExtraListeners added in v0.12.0

func ExtraListeners(lns ...listeners.Listener) Option

func Handlers added in v0.13.3

func Handlers(handlers ...server.Handler) Option

func MAXPROCS added in v0.12.0

func MAXPROCS(min int, max int) Option

func RegisterValidator added in v0.12.0

func RegisterValidator(register validators.ValidateRegister) Option

func SecretKey added in v0.12.0

func SecretKey(data string) Option

func Server added in v0.12.0

func Server(server server.Http) Option

func ShutdownTimeout added in v0.12.0

func ShutdownTimeout(timeout time.Duration) Option

func Version

func Version(version string) Option

type Options

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

Jump to

Keyboard shortcuts

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