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
- DDD
- Extra listeners
- Third party integration
- Oauth
- Payments
- SMS
- Notifications
Quickstart
Create project
First: install fnc
commander.
go install github.com/aacfactory/fnc
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