Documentation ¶
Index ¶
- Constants
- Variables
- func OpenAPIHandler(c *Context) (interface{}, error)
- func ShutdownWithContext(ctx context.Context, shutdownFunc func(ctx context.Context) error, ...) error
- func SwaggerUIHandler(c *Context) (interface{}, error)
- type App
- func (a *App) AddCassandra(db container.CassandraProvider)
- func (a *App) AddClickhouse(db container.ClickhouseProvider)
- func (a *App) AddCronJob(schedule, jobName string, job CronFunc)
- func (a *App) AddDgraph(db container.DgraphProvider)
- func (a *App) AddFTP(fs file.FileSystemProvider)
- func (a *App) AddFileStore(fs file.FileSystemProvider)
- func (a *App) AddHTTPService(serviceName, serviceAddress string, options ...service.Options)
- func (a *App) AddKVStore(db container.KVStoreProvider)
- func (a *App) AddMongo(db container.MongoProvider)
- func (a *App) AddPubSub(pubsub container.PubSubProvider)
- func (a *App) AddRESTHandlers(object interface{}) error
- func (a *App) AddSolr(db container.SolrProvider)
- func (a *App) AddStaticFiles(endpoint, filePath string)
- func (a *App) DELETE(pattern string, handler Handler)
- func (a *App) EnableAPIKeyAuth(apiKeys ...string)
- func (a *App) EnableAPIKeyAuthWithFunc(validateFunc func(apiKey string) bool)deprecated
- func (a *App) EnableAPIKeyAuthWithValidator(validateFunc func(c *container.Container, apiKey string) bool)
- func (a *App) EnableBasicAuth(credentials ...string)
- func (a *App) EnableBasicAuthWithFunc(validateFunc func(username, password string) bool)deprecated
- func (a *App) EnableBasicAuthWithValidator(validateFunc func(c *container.Container, username, password string) bool)
- func (a *App) EnableOAuth(jwksEndpoint string, refreshInterval int)
- func (a *App) GET(pattern string, handler Handler)
- func (a *App) Logger() logging.Logger
- func (a *App) Metrics() metrics.Manager
- func (a *App) Migrate(migrationsMap map[int64]migration.Migrate)
- func (a *App) OverrideWebsocketUpgrader(wsUpgrader websocket.Upgrader)
- func (a *App) PATCH(pattern string, handler Handler)
- func (a *App) POST(pattern string, handler Handler)
- func (a *App) PUT(pattern string, handler Handler)
- func (a *App) RegisterService(desc *grpc.ServiceDesc, impl any)
- func (a *App) Run()
- func (a *App) Shutdown(ctx context.Context) error
- func (a *App) SubCommand(pattern string, handler Handler, options ...Options)
- func (a *App) Subscribe(topic string, handler SubscribeFunc)
- func (a *App) UseMiddleware(middlewares ...gofrHTTP.Middleware)
- func (a *App) UseMongo(db container.Mongo)
- func (a *App) WebSocket(route string, handler Handler)
- type CRUD
- type Context
- type Create
- type CronFunc
- type Crontab
- type Delete
- type ErrCommandNotFound
- type ErrorLogEntry
- type Exporter
- type Get
- type GetAll
- type Handler
- type Options
- type Request
- type Responder
- type RestPathOverrider
- type Span
- type SubscribeFunc
- type SubscriptionManager
- type TableNameOverrider
- type Update
Constants ¶
const (
OpenAPIJSON = "openapi.json"
)
Variables ¶
var ErrMarshalingResponse = errors.New("error marshaling response")
Functions ¶
func OpenAPIHandler ¶ added in v1.0.0
OpenAPIHandler serves the `openapi.json` file at the specified path. It reads the file from the disk and returns its content as a response.
func ShutdownWithContext ¶ added in v1.16.0
func ShutdownWithContext(ctx context.Context, shutdownFunc func(ctx context.Context) error, forceCloseFunc func() error) error
ShutdownWithContext handles the shutdown process with context timeout. It takes a shutdown function and a force close function as parameters. If the context times out, the force close function is called.
func SwaggerUIHandler ¶ added in v1.0.0
SwaggerUIHandler serves the static files of the Swagger UI.
Types ¶
type App ¶
type App struct { // Config can be used by applications to fetch custom configurations from environment or file. Config config.Config // If we directly embed, unnecessary confusion between app.Get and app.GET will happen. // contains filtered or unexported fields }
App is the main application in the GoFr framework.
func (*App) AddCassandra ¶ added in v1.9.0
func (a *App) AddCassandra(db container.CassandraProvider)
AddCassandra sets the Cassandra datasource in the app's container.
func (*App) AddClickhouse ¶ added in v1.10.0
func (a *App) AddClickhouse(db container.ClickhouseProvider)
AddClickhouse initializes the clickhouse client. Official implementation is available in the package : gofr.dev/pkg/gofr/datasource/clickhouse .
func (*App) AddCronJob ¶ added in v1.6.0
AddCronJob registers a cron job to the cron table. The cron expression can be either a 5-part or 6-part format. The 6-part format includes an optional second field (in beginning) and others being minute, hour, day, month and day of week respectively.
func (*App) AddDgraph ¶ added in v1.21.0
func (a *App) AddDgraph(db container.DgraphProvider)
AddDgraph sets the Dgraph datasource in the app's container.
func (*App) AddFTP ¶ added in v1.17.0
func (a *App) AddFTP(fs file.FileSystemProvider)
AddFTP sets the FTP datasource in the app's container. Deprecated: Use the AddFile method instead.
func (*App) AddFileStore ¶ added in v1.19.0
func (a *App) AddFileStore(fs file.FileSystemProvider)
AddFile sets the FTP,SFTP,S3 datasource in the app's container.
func (*App) AddHTTPService ¶
AddHTTPService registers HTTP service in container.
func (*App) AddKVStore ¶ added in v1.15.0
func (a *App) AddKVStore(db container.KVStoreProvider)
AddKVStore sets the KV-Store datasource in the app's container.
func (*App) AddMongo ¶ added in v1.7.0
func (a *App) AddMongo(db container.MongoProvider)
AddMongo sets the Mongo datasource in the app's container.
func (*App) AddPubSub ¶ added in v1.22.0
func (a *App) AddPubSub(pubsub container.PubSubProvider)
AddPubSub sets the PubSub client in the app's container.
func (*App) AddRESTHandlers ¶ added in v1.3.0
AddRESTHandlers creates and registers CRUD routes for the given struct, the struct should always be passed by reference.
func (*App) AddSolr ¶ added in v1.20.0
func (a *App) AddSolr(db container.SolrProvider)
AddSolr sets the Solr datasource in the app's container.
func (*App) AddStaticFiles ¶ added in v1.12.0
AddStaticFiles registers a static file endpoint for the application.
The provided `endpoint` will be used as the prefix for the static file server. The `filePath` specifies the directory containing the static files. If `filePath` starts with "./", it will be interpreted as a relative path to the current working directory.
func (*App) EnableAPIKeyAuth ¶ added in v1.1.1
EnableAPIKeyAuth enables API key authentication for the application.
It requires at least one API key to be provided. The provided API keys will be used to authenticate requests.
func (*App) EnableAPIKeyAuthWithFunc
deprecated
added in
v1.1.1
func (*App) EnableAPIKeyAuthWithValidator ¶ added in v1.11.0
func (a *App) EnableAPIKeyAuthWithValidator(validateFunc func(c *container.Container, apiKey string) bool)
EnableAPIKeyAuthWithValidator enables API key authentication for the application with a custom validation function.
The provided `validateFunc` is used to determine the validity of an API key. It receives the request container and the API key as arguments and should return `true` if the key is valid, `false` otherwise.
func (*App) EnableBasicAuth ¶ added in v1.1.1
EnableBasicAuth enables basic authentication for the application.
It takes a variable number of credentials as alternating username and password strings. An error is logged if an odd number of arguments is provided.
func (*App) EnableBasicAuthWithFunc
deprecated
added in
v1.1.1
func (*App) EnableBasicAuthWithValidator ¶ added in v1.11.0
func (a *App) EnableBasicAuthWithValidator(validateFunc func(c *container.Container, username, password string) bool)
EnableBasicAuthWithValidator enables basic authentication for the HTTP server with a custom validator.
The provided `validateFunc` is invoked for each authentication attempt. It receives a container instance, username, and password. The function should return `true` if the credentials are valid, `false` otherwise.
func (*App) EnableOAuth ¶ added in v1.1.1
EnableOAuth configures OAuth middleware for the application.
It registers a new HTTP service for fetching JWKS and sets up OAuth middleware with the given JWKS endpoint and refresh interval.
The JWKS endpoint is used to retrieve JSON Web Key Sets for verifying tokens. The refresh interval specifies how often to refresh the token cache.
func (*App) Migrate ¶ added in v0.3.0
Migrate applies a set of migrations to the application's database.
The migrationsMap argument is a map where the key is the version number of the migration and the value is a migration.Migrate instance that implements the migration logic.
func (*App) OverrideWebsocketUpgrader ¶ added in v1.10.0
func (*App) RegisterService ¶
func (a *App) RegisterService(desc *grpc.ServiceDesc, impl any)
RegisterService adds a gRPC service to the GoFr application.
func (*App) Run ¶
func (a *App) Run()
Run starts the application. If it is an HTTP server, it will start the server.
func (*App) Shutdown ¶ added in v1.16.0
Shutdown stops the service(s) and close the application. It shuts down the HTTP, gRPC, Metrics servers and closes the container's active connections to datasources.
func (*App) SubCommand ¶
SubCommand adds a sub-command to the CLI application. Can be used to create commands like "kubectl get" or "kubectl get ingress".
func (*App) Subscribe ¶ added in v1.1.1
func (a *App) Subscribe(topic string, handler SubscribeFunc)
Subscribe registers a handler for the given topic.
If the subscriber is not initialized in the container, an error is logged and the subscription is not registered.
func (*App) UseMiddleware ¶ added in v1.5.0
func (a *App) UseMiddleware(middlewares ...gofrHTTP.Middleware)
UseMiddleware is a setter method for adding user defined custom middleware to GoFr's router.
func (*App) UseMongo ¶ added in v1.3.0
UseMongo sets the Mongo datasource in the app's container. Deprecated: Use the AddMongo method instead.
func (*App) WebSocket ¶ added in v1.10.0
WebSocket registers a handler function for a WebSocket route. This method allows you to define a route handler for WebSocket connections. It internally handles the WebSocket handshake and provides a `websocket.Connection` object within the handler context. User can access the underlying WebSocket connection using `ctx.GetWebsocketConnection()`.
type Context ¶
type Context struct { context.Context // Request needs to be public because handlers need to access request details. Else, we need to provide all // functionalities of the Request as a method on context. This is not needed because Request here is an interface // So, internals are not exposed anyway. Request // Same logic as above. *container.Container // contains filtered or unexported fields }
func (*Context) Trace ¶
Trace returns an open telemetry span. We have to always close the span after corresponding work is done. Usages:
span := c.Trace("Some Work") // Do some work here. defer span.End()
If an entire function has to traced as span, we can use a simpler format:
defer c.Trace("ExampleHandler").End()
We can write this at the start of function and because of how defer works, trace will start at that line but End will be called after function ends.
Developer Note: If you chain methods in a defer statement, everything except the last function will be evaluated at call time.
func (*Context) WriteMessageToSocket ¶ added in v1.17.0
WriteMessageToSocket writes a message to the WebSocket connection associated with the context. The data parameter can be of type string, []byte, or any struct that can be marshaled to JSON. It retrieves the WebSocket connection from the context and sends the message as a TextMessage.
type Crontab ¶ added in v1.0.0
type Crontab struct {
// contains filtered or unexported fields
}
Crontab maintains the job scheduling and runs the jobs at their scheduled time by going through them at each tick using a ticker.
type ErrCommandNotFound ¶
type ErrCommandNotFound struct{}
func (ErrCommandNotFound) Error ¶
func (ErrCommandNotFound) Error() string
type ErrorLogEntry ¶ added in v1.18.0
type ErrorLogEntry struct { TraceID string `json:"trace_id,omitempty"` Error string `json:"error,omitempty"` }
func (*ErrorLogEntry) PrettyPrint ¶ added in v1.18.0
func (el *ErrorLogEntry) PrettyPrint(writer io.Writer)
type Exporter ¶ added in v1.4.0
type Exporter struct {
// contains filtered or unexported fields
}
Exporter is responsible for exporting spans to a remote endpoint.
func NewExporter ¶ added in v1.4.0
NewExporter creates a new Exporter instance with a custom endpoint and logger.
func (*Exporter) ExportSpans ¶ added in v1.4.0
ExportSpans exports spans to the configured remote endpoint.
type Options ¶ added in v1.9.0
type Options func(c *route)
func AddDescription ¶ added in v1.9.0
AddDescription adds the description text for a specified subcommand.
type Request ¶
type Request interface { Context() context.Context Param(string) string PathParam(string) string Bind(interface{}) error HostName() string Params(string) []string }
Request is an interface which is written because it allows us to create applications without being aware of the transport. In both cmd or server application, this abstraction can be used.
type Responder ¶
type Responder interface {
Respond(data interface{}, err error)
}
Responder is used by the application to provide output. This is implemented for both cmd and HTTP server application.
type RestPathOverrider ¶ added in v1.8.0
type RestPathOverrider interface {
RestPath() string
}
type Span ¶ added in v1.4.0
type Span struct { TraceID string `json:"traceId"` // Trace ID of the span. ID string `json:"id"` // ID of the span. ParentID string `json:"parentId,omitempty"` // Parent ID of the span. Name string `json:"name"` // Name of the span. Timestamp int64 `json:"timestamp"` // Timestamp of the span. Duration int64 `json:"duration"` // Duration of the span. Tags map[string]string `json:"tags,omitempty"` // Tags associated with the span. LocalEndpoint map[string]string `json:"localEndpoint"` // Local endpoint of the span. }
Span represents a span that will be exported.
type SubscribeFunc ¶ added in v1.1.1
type SubscriptionManager ¶ added in v1.1.1
type SubscriptionManager struct {
// contains filtered or unexported fields
}
type TableNameOverrider ¶ added in v1.8.0
type TableNameOverrider interface {
TableName() string
}
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
Package container is a generated GoMock package.
|
Package container is a generated GoMock package. |
file
Package file is a generated GoMock package.
|
Package file is a generated GoMock package. |
pubsub
Package pubsub provides a foundation for implementing pub/sub clients for various message brokers such as google pub-sub, kafka and MQTT.
|
Package pubsub provides a foundation for implementing pub/sub clients for various message brokers such as google pub-sub, kafka and MQTT. |
pubsub/google
Package google provides a client for interacting with Google Cloud Pub/Sub.This package facilitates interaction with Google Cloud Pub/Sub, allowing publishing and subscribing to topics, managing subscriptions, and handling messages.
|
Package google provides a client for interacting with Google Cloud Pub/Sub.This package facilitates interaction with Google Cloud Pub/Sub, allowing publishing and subscribing to topics, managing subscriptions, and handling messages. |
pubsub/kafka
Package kafka provides a client for interacting with Apache Kafka message queues.This package facilitates interaction with Apache Kafka, allowing publishing and subscribing to topics, managing consumer groups, and handling messages.
|
Package kafka provides a client for interacting with Apache Kafka message queues.This package facilitates interaction with Apache Kafka, allowing publishing and subscribing to topics, managing consumer groups, and handling messages. |
pubsub/mqtt
Package mqtt provides a client for interacting with MQTT message brokers.This package facilitates interaction with MQTT brokers, allowing publishing and subscribing to topics, managing subscriptions, and handling messages.
|
Package mqtt provides a client for interacting with MQTT message brokers.This package facilitates interaction with MQTT brokers, allowing publishing and subscribing to topics, managing subscriptions, and handling messages. |
redis
Package redis provides a client for interacting with Redis key-value stores.This package allows creating and managing Redis clients, executing Redis commands, and handling connections to Redis databases.
|
Package redis provides a client for interacting with Redis key-value stores.This package allows creating and managing Redis clients, executing Redis commands, and handling connections to Redis databases. |
sql
Package sql provides functionalities to interact with SQL databases using the database/sql package.This package includes a wrapper around sql.DB and sql.Tx to provide additional features such as query logging, metrics recording, and error handling.
|
Package sql provides functionalities to interact with SQL databases using the database/sql package.This package includes a wrapper around sql.DB and sql.Tx to provide additional features such as query logging, metrics recording, and error handling. |
cassandra
Module
|
|
clickhouse
Module
|
|
dgraph
Module
|
|
file/ftp
Module
|
|
file/s3
Module
|
|
file/sftp
Module
|
|
kv-store/badger
Module
|
|
mongo
Module
|
|
pubsub/eventhub
Module
|
|
pubsub/nats
Module
|
|
solr
Module
|
|
Package http provides a set of utilities for handling HTTP requests and responses within the GoFr framework.
|
Package http provides a set of utilities for handling HTTP requests and responses within the GoFr framework. |
middleware
Package middleware provides a collection of middleware functions that handles various aspects of request handling, such as authentication, logging, tracing, and metrics collection.
|
Package middleware provides a collection of middleware functions that handles various aspects of request handling, such as authentication, logging, tracing, and metrics collection. |
Package logging provides logging functionalities for GoFr applications.
|
Package logging provides logging functionalities for GoFr applications. |
Package metrics provides functionalities for instrumenting GoFr applications with metrics.
|
Package metrics provides functionalities for instrumenting GoFr applications with metrics. |
Package migration is a generated GoMock package.
|
Package migration is a generated GoMock package. |
Package service provides an HTTP client with features for logging, metrics, and resilience.It supports various functionalities like health checks, circuit-breaker and various authentication.
|
Package service provides an HTTP client with features for logging, metrics, and resilience.It supports various functionalities like health checks, circuit-breaker and various authentication. |
Package websocket is a generated GoMock package.
|
Package websocket is a generated GoMock package. |