modulepackage
2.0.1+incompatible
Repository: https://github.com/pitabwire/frame.git
Documentation: pkg.go.dev
# README
frame 
A simple frame for quickly setting up api servers based on gocloud framework.
Features include:
- An http server
- A grpc server
- Database setup using Gorm with migrations and multitenancy support
- Easy queue publish and subscription support
- Localization
- Authentication adaptor for oauth2 and jwt access
- Authorization adaptor
The goal of this project is to simplify starting up servers with minimal boiler plate code. All components are very pluggable with only the necessary configured items loading at runtime thanks to the power of go-cloud under the hood.
Getting started:
go get -u github.com/pitabwire/frame
Example
import (
"context"
"fmt"
"github.com/gorilla/mux"
"github.com/pitabwire/frame"
"log"
"net/http"
)
func handler(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "Frame says yelloo!")
}
func main() {
serviceName := "service_authentication"
ctx := context.Background()
router := mux.NewRouter().StrictSlash(true)
router.HandleFunc("/", handler)
server := frame.HttpHandler(router)
service := frame.NewService(serviceName,server)
err := service.Run(ctx, ":7654")
if err != nil {
log.Fatal("main -- Could not run Server : %v", err)
}
}
Detailed guides can be found here
development
To run tests start the docker compose file in ./tests then run :
go test -json -cover ./...
# Functions
AuthHasAccess binary check to confirm if subject can perform action specified.
BackGroundConsumer Option to register a background processing function that is initialized before running servers this function is maintained alive using the same error group as the servers so that if any exit earlier due to error all stop functioning.
ClaimsFromContext extracts authentication claims from the supplied context if any exist.
ClaimsFromMap extracts authentication claims from the supplied map if they exist.
Config Option that helps to specify or override the configuration object of our service.
ConfigProcess convenience method to process configs.
CorsPolicy Option to specify the cors policy to utilize on the client.
No description provided by the author
DatastoreCon Option method to store a connection that will be utilized when connecting to the database.
DBErrorIsRecordNotFound validate if supplied error is because of record missing in DB.
DBPropertiesFromMap converts a map into a JSONMap object.
DBPropertiesToMap converts the supplied db json content into a golang map.
FromContext obtains a service instance being propagated through the context.
GetEnv Obtains the environment key or returns the default value.
GetIp convenience method to extract the remote ip address from our inbound request.
GetLocalIP convenince method that obtains the non localhost ip address for machine running app.
GetMacAddress convenience method to get some unique address based on the network interfaces the application is running on.
GrpcServer Option to specify an instantiated grpc server with an implementation that can be utilized to handle incoming requests.
HandleLive is an http.HandlerFunc that handles liveness checks by immediately responding with an HTTP 200 status.
HttpHandler Option to specify an http handler that can be used to handle inbound http requests.
LivelinessPath Option checks that the system is up and running.
Logger Option that helps with initialization of our internal logger.
No description provided by the author
NewService creates a new instance of Service with the name and supplied options It is used together with the Init option to setup components of a service that is not yet running.
NoopDriver Option to force the underlying http driver to not listen on a port.
ReadinessPath Option checks that the system is ready to receive requests.
RegisterEvents Option to write an event or list of events into the service registry for future use.
RegisterPublisher Option to register publishing path referenced within the system.
RegisterSubscriber Option to register a new subscription handler.
ServerListener Option to specify user preferred listener instead of the default provided one.
ToContext pushes a service instance into the supplied context for easier propagation.
TraceExporter Option that specify the trace exporter to use.
TraceSampler Option that specify the trace sampler to use.
Translations Option to initialize/load different language packs.
WithConcurrency Option sets the count of pool workers to handle server load.
# Structs
AuthenticationClaims Create a struct that will be encoded to a JWT.
BaseModel base table struct to be extended by other models.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
Migration Our simple table holding all the migration data.
Service framework struct to hold together all application components An instance of this type scoped to stay for the lifetime of the application.
# Interfaces
No description provided by the author
No description provided by the author
Checker wraps the CheckHealth method.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
EventI an interface to represent a system event.
No description provided by the author
No description provided by the author
# Type aliases
CheckerFunc is an adapter type to allow the use of ordinary functions as health checks.
No description provided by the author