gofr.dev

module
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Dec 29, 2023 License: Apache-2.0

README

GoFr

logo


Gofr is an opinionated microservice development framework. Listed in CNCF Landscape.

Visit https://gofr.dev for more details and documentation.

🎯 Goal

Even though generic applications can be written using Gofr, our main focus is to simplify the development of microservices. We will focus ourselves towards deployment in kubernetes and aspire to provide out-of-the-box observability.

⚡️ Quick Start Guide

If you already have a go project with go module, you can get gofr by calling: go get gofr.dev. Follow the instructions below, if you are starting afresh.

The latest version of go in your system should be installed. If you have not already done that, install it from here. This can be tested by opening a terminal and trying go version. One should also be familiar with golang syntax. Official golang website has an excellent tour of go and is highly recommended.

Writing an API service using Gofr is very simple.

  1. In an empty folder, initialise your go module using: go mod init test-service. If you intend to push your code to github, it is recommended to name your module like this: go mod init github.com/{USERNAME}/{REPO}
  2. Create main.go file with following content:
package main

import "gofr.dev/pkg/gofr"

func main() {
    app := gofr.New()

    app.GET("/", func(ctx *gofr.Context) (interface{}, error) {
        return "Hello World!", nil
    })

    app.Start()
}
  1. Get all the dependencies using go get ./.... It will download gofr along with every other package it requires.
  2. Start the server: go run main.go It will start the server on default port 8000. If this port is already in use, you can override the default port by mentioning an environment variable like this: HTTP_PORT=9000 go run main.go

💡 Advantages/Features

  1. Simple API syntax
  2. REST Standards by default
  3. Battle Tested at Enterprise Scale
  4. Configuration management
  5. Database state management using migrations
  6. Inbuilt Middlewares along with support for custom middlewares
  7. Error Management
  8. Inbuilt Datastore, File System, Pub/Sub
  9. gRPC support
  10. Chained timeout control
  11. Serve Static Files
  12. Websocket
  13. Support for Surge Protection
  14. Inbuilt Traces, Metrics and Logs

👍 Contribute

If you want to say thank you and/or support the active development of GoFr:

  1. Add a GitHub Star to the project.
  2. Write a review or tutorial on Medium, Dev.to or personal blog.
  3. Visit CONTRIBUTING for details on submitting patches and the contribution workflow.

Directories

Path Synopsis
cli
gofr Module
cmd
gofr/addRoute
Package mock_addRoute is a generated GoMock package.
Package mock_addRoute is a generated GoMock package.
gofr/entity
Package mock_entity is a generated GoMock package.
Package mock_entity is a generated GoMock package.
gofr/initialize
Package initialize is a generated GoMock package.
Package initialize is a generated GoMock package.
gofr/migration/handler
Package handler is a generated GoMock package.
Package handler is a generated GoMock package.
gofr/test
Package test provides a command line interface for running tests for a given openapi specification.
Package test provides a command line interface for running tests for a given openapi specification.
examples
universal-example/cassandra/store
Package mock_store is a generated GoMock package.
Package mock_store is a generated GoMock package.
using-awssns/handlers
Package handlers is a generated GoMock package.
Package handlers is a generated GoMock package.
using-cassandra/migrations
This is auto-generated file using 'gofr migrate' tool.
This is auto-generated file using 'gofr migrate' tool.
using-cassandra/stores
Package stores is a generated GoMock package.
Package stores is a generated GoMock package.
using-clickhouse/migrations
This is auto-generated file using 'gofr migrate' tool.
This is auto-generated file using 'gofr migrate' tool.
using-clickhouse/store
Package store is a generated GoMock package.
Package store is a generated GoMock package.
using-dynamodb/stores
Package stores is a generated GoMock package.
Package stores is a generated GoMock package.
using-http-service/services
Package services is a generated GoMock package.
Package services is a generated GoMock package.
using-mongo/stores
Package stores is a generated GoMock package.
Package stores is a generated GoMock package.
using-mysql/store
Package store is a generated GoMock package.
Package store is a generated GoMock package.
using-postgres/migrations
This is auto-generated file using 'gofr migrate' tool.
This is auto-generated file using 'gofr migrate' tool.
using-ycql/migrations
This is auto-generated file using 'gofr migrate' tool.
This is auto-generated file using 'gofr migrate' tool.
using-ycql/stores
Package stores is a generated GoMock package.
Package stores is a generated GoMock package.
pkg
datastore/pubsub
Package pubsub implements the necessary methods and types to work with publish-subscribe messaging patterns.
Package pubsub implements the necessary methods and types to work with publish-subscribe messaging patterns.
datastore/pubsub/avro
Package avro provides implementation methods for working with avro to serialize and deserialize messages.
Package avro provides implementation methods for working with avro to serialize and deserialize messages.
datastore/pubsub/eventbridge
Package eventbridge provides methods to interact with AWS Eventbridge service allowing user to publish events to Eventbridge
Package eventbridge provides methods to interact with AWS Eventbridge service allowing user to publish events to Eventbridge
datastore/pubsub/eventhub
Package eventhub provides methods to interact, publish and consume events from Azure Eventhub
Package eventhub provides methods to interact, publish and consume events from Azure Eventhub
datastore/pubsub/google
Package google provides methods to work with Google Cloud Pub/Sub enabling the publishing and consumption of messages.
Package google provides methods to work with Google Cloud Pub/Sub enabling the publishing and consumption of messages.
datastore/pubsub/kafka
Package kafka provides methods to interact with Apache Kafka offering functionality for both producing and consuming messages from kafka-topics.
Package kafka provides methods to interact with Apache Kafka offering functionality for both producing and consuming messages from kafka-topics.
errors
Package errors have the predefined errors that can be used to denote various types of errors
Package errors have the predefined errors that can be used to denote various types of errors
file
Package file provides various functionalities for reading, writing and manipulating files and supports different file storage backends like aws, azure, gcp, sftp, ftp along with the support for local files.
Package file provides various functionalities for reading, writing and manipulating files and supports different file storage backends like aws, azure, gcp, sftp, ftp along with the support for local files.
gofr
Package gofr provides a comprehensive framework for building web applications following RESTful principles.
Package gofr provides a comprehensive framework for building web applications following RESTful principles.
gofr/assert
Package assert provides the functionality to check the correctness of the output of a command line function
Package assert provides the functionality to check the correctness of the output of a command line function
gofr/cache
Package cache implements a basic redis cache which provides functionality to interact with redis
Package cache implements a basic redis cache which provides functionality to interact with redis
gofr/config
Package config provides the functionality to read environment variables it has the power to read from a static config file or from a remote config server
Package config provides the functionality to read environment variables it has the power to read from a static config file or from a remote config server
gofr/metrics
Package metrics provides the functionality to create custom metrics for applications
Package metrics provides the functionality to create custom metrics for applications
gofr/request
Package request provides the implementation of operations related to a http and cmd request it gives the features like reading parameters, bind request body, etc.
Package request provides the implementation of operations related to a http and cmd request it gives the features like reading parameters, bind request body, etc.
gofr/responder
Package responder provides the functionality to populate the responses for the respective incoming requests
Package responder provides the functionality to populate the responses for the respective incoming requests
gofr/template
Package template provides the functionality to render html pages based on the html/templates provided by go
Package template provides the functionality to render html pages based on the html/templates provided by go
gofr/types
Package types provides most common structures that can be used in a http server This package also implements a validation function for all the types that check the validity of the values in the fields of these structures
Package types provides most common structures that can be used in a http server This package also implements a validation function for all the types that check the validity of the values in the fields of these structures
log
Package log provides logger for logging various output messages in different formats, including color-coded terminal output and JSON.Gofr logger supports different log levels such as INFO, ERROR, WARN, DEBUG, or FATAL.
Package log provides logger for logging various output messages in different formats, including color-coded terminal output and JSON.Gofr logger supports different log levels such as INFO, ERROR, WARN, DEBUG, or FATAL.
middleware
Package middleware provides set of middleware functions that can be used to authenticate and authorize requests in HTTP server.It also supports handling CORS, propagating headers, integrating with New Relic APM, and enabling distributed tracing using OpenTelemetry.
Package middleware provides set of middleware functions that can be used to authenticate and authorize requests in HTTP server.It also supports handling CORS, propagating headers, integrating with New Relic APM, and enabling distributed tracing using OpenTelemetry.
middleware/oauth
Package oauth provides a middleware for authenticating requests.This package provides functionality for token validation and integration with JSON Web Key (JWK) to verify JSON Web Tokens (JWT).
Package oauth provides a middleware for authenticating requests.This package provides functionality for token validation and integration with JSON Web Key (JWK) to verify JSON Web Tokens (JWT).
notifier
Package notifier defines Notifier interface and Message struct responsible for facilitating communication and coordination between different components of an application.
Package notifier defines Notifier interface and Message struct responsible for facilitating communication and coordination between different components of an application.
notifier/aws-sns
Package awssns provides notifier implementation for AWS Simple Notification Service(SNS) to publish-subscribe messages to an SNS topic.It offers features like message attribute customization and health checks to ensure the notifier's availability.
Package awssns provides notifier implementation for AWS Simple Notification Service(SNS) to publish-subscribe messages to an SNS topic.It offers features like message attribute customization and health checks to ensure the notifier's availability.
service
Package service provides generic HTTP client that can be used to call remote services.The service package also provides support for custom headers, authentication, caching settings, and surge protection options.The package defines three main interfaces: HTTP, SOAP, and Cacher, which can be used to implement various service clients.
Package service provides generic HTTP client that can be used to call remote services.The service package also provides support for custom headers, authentication, caching settings, and surge protection options.The package defines three main interfaces: HTTP, SOAP, and Cacher, which can be used to implement various service clients.
Package web provides the functionality to read swagger files
Package web provides the functionality to read swagger files

Jump to

Keyboard shortcuts

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