gofr.dev

module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2023 License: Apache-2.0

README

Gofr

Gofr is an opinionated microservice development framework.

In order to fetch Gofr as a dependency

go get gofr.dev

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.

Contribution Guidelines

  • Minor changes can be done directly by editing code on github. Github automatically creates a temporary branch and files a PR. This is only suitable for really small changes like: spelling fixes, variable name changes or error string change etc. For larger commits, following steps are recommended.
  • (Optional) If you want to discuss your implementation with the users of Gofr, use the github discussions of this repo.
  • Configure your editor to use goimport and golangci-lint on file changes. Any code which is not formatted using these tools, will fail on the pipeline.
  • All code contributions should have associated tests and all new line additions should be covered in those testcases. No PR should ever decrease the overall code coverage.
  • Once your code changes are done along with the testcases, submit a PR to development branch. Please note that all PRs are merged from feature branches to development first.
  • All PRs need to be reviewed by at least 2 Gofr developers. They might reach out to you for any clarfication.
  • Thank you for your contribution. :)

Testing

Some services will be required to pass the entire test suite. We recommend using docker for running those services.

docker run --name gofr-mysql -e MYSQL_ROOT_PASSWORD=password -p 2001:3306 -d mysql:8.0.30
docker run --name gofr-redis -p 2002:6379 -d redis:7.0.5
docker run --name gofr-cassandra -d -p 2003:9042 cassandra:4.1
docker run --name gofr-solr -p 2020:8983 solr:8 -DzkRun
docker run --name gofr-mongo -d -e MONGO_INITDB_ROOT_USERNAME=admin -e MONGO_INITDB_ROOT_PASSWORD=admin123 -p 2004:27017 mongo:6.0.2
docker run --name gofr-zipkin -d -p 2005:9411 openzipkin/zipkin:2
docker run --name gofr-pgsql -d -e POSTGRES_DB=customers -e POSTGRES_PASSWORD=root123 -p 2006:5432 postgres:15.1
docker run --name gofr-mssql -d -e 'ACCEPT_EULA=Y' -e 'SA_PASSWORD=reallyStrongPwd123' -p 2007:1433 mcr.microsoft.com/azure-sql-edge
docker run --rm -d -p 2181:2181 -p 443:2008 -p 2008:2008 -p 2009:2009 \
    --env ADVERTISED_LISTENERS=PLAINTEXT://localhost:443,INTERNAL://localhost:2009 \
    --env LISTENERS=PLAINTEXT://0.0.0.0:2008,INTERNAL://0.0.0.0:2009 \
    --env SECURITY_PROTOCOL_MAP=PLAINTEXT:PLAINTEXT,INTERNAL:PLAINTEXT \
    --env INTER_BROKER=INTERNAL \
    --env KAFKA_CREATE_TOPICS="test-topic,test:36:1,krisgeus:12:1:compact" \
    --name gofr-kafka \
    krisgeus/docker-kafka

docker run --name gofr-yugabyte -p 2011:9042 -d yugabytedb/yugabyte:2.14.5.0-b18 bin/yugabyted start --daemon=false  
docker run -d --name gofr-elasticsearch -p 2012:9200 -p 2013:9300 -e "discovery.type=single-node" elasticsearch:6.8.6 
docker run -d --name gofr-dynamodb -p 2021:8000 amazon/dynamodb-local:1.22.0
docker run -d --name=gofr-cockroachdb -p 26257:26257 cockroachdb/cockroach:v21.2.4 start-single-node --insecure
docker run --name=gcloud-emulator -d -p 8086:8086 gcr.io/google.com/cloudsdktool/google-cloud-cli:emulators gcloud beta emulators pubsub start --project=test123 \
    --host-port=0.0.0.0:8086

Please note that the recommended local port for the services are different than the actual ports. This is done to avoid conflict with the local installation on developer machines. This method also allows a developer to work on multiple projects which uses the same services but bound on different ports. One can choose to change the port for these services. Just remember to add the same in configs/.local.env, if you decide to do that.

Coding Guidelines

  • Use only what is given to you as part of function parameter or receiver. No globals. Inject all dependencies including DB, Logger etc.
  • No magic. So, no init. In a large project, it becomes difficult to track which package is doing what at the initialisation step.
  • Exported functions must have an associated goDoc.
  • Sensitive data(username, password, keys) should not be pushed. Always use environment variables.
  • Take interfaces and return concrete types.
    • Lean interfaces - take 'exactly' what you need, not more. Onus of interface definition is on the package who is using it. so, it should be as lean as possible. This makes it easier to test.
    • Be careful of type assertions in this context. If you take an interface and type assert to a type - then its similar to taking concrete type.
  • Uses of context:
    • We should use context as a first parameter.
    • Can not use string as a key for the context. Define your own type and provide context accessor method to avoid conflict.
  • External Library uses:
    • A little copying is better than a little dependency.
    • All external dependencies should go through the same careful consideration, we would have done to our own written code. We need to test the functionality we are going to use from an external library, as sometimes library implementation may change.
    • All dependencies must be abstracted as an interface. This will make it easier to switch libraries at later point of time.
  • Version tagging as per Semantic versioning (https://semver.org/)

Directories

Path Synopsis
cli
gofr module
cmd
gofr command
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 mock_initialize is a generated GoMock package.
Package mock_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
cmd-example command
fileResponse command
sample-api command
sample-cron command
sample-grpc command
sample-https command
tracing command
universal-example/cassandra/store
Package mock_store is a generated GoMock package.
Package mock_store is a generated GoMock package.
using-avro command
using-awssns command
using-awssns/handlers
Package handlers is a generated GoMock package.
Package handlers is a generated GoMock package.
using-cassandra command
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-dynamodb command
using-dynamodb/stores
Package stores is a generated GoMock package.
Package stores is a generated GoMock package.
using-eventhub command
using-file command
using-http-service/services
Package services is a generated GoMock package.
Package services is a generated GoMock package.
using-http2 command
using-mongo command
using-mongo/stores
Package stores is a generated GoMock package.
Package stores is a generated GoMock package.
using-mysql command
using-mysql/store
Package store is a generated GoMock package.
Package store is a generated GoMock package.
using-postgres command
using-postgres/migrations
This is auto-generated file using 'gofr migrate' tool.
This is auto-generated file using 'gofr migrate' tool.
using-pubsub command
using-redis command
using-solr command
using-ycql command
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