![logo](https://private-user-images.githubusercontent.com/324203/277672106-b3b27007-9501-4212-816a-422bfd02cd42.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjM0OTczOTIsIm5iZiI6MTcyMzQ5NzA5MiwicGF0aCI6Ii8zMjQyMDMvMjc3NjcyMTA2LWIzYjI3MDA3LTk1MDEtNDIxMi04MTZhLTQyMmJmZDAyY2Q0Mi5wbmc_WC1BbXotQWxnb3JpdGhtPUFXUzQtSE1BQy1TSEEyNTYmWC1BbXotQ3JlZGVudGlhbD1BS0lBVkNPRFlMU0E1M1BRSzRaQSUyRjIwMjQwODEyJTJGdXMtZWFzdC0xJTJGczMlMkZhd3M0X3JlcXVlc3QmWC1BbXotRGF0ZT0yMDI0MDgxMlQyMTExMzJaJlgtQW16LUV4cGlyZXM9MzAwJlgtQW16LVNpZ25hdHVyZT1jMTNjMzQ2NmZlOWY1MWUwMTkxM2RjMDU4NDM5NWY4M2IyMjczMTcwZDEzNDlhNzhjNDc4YWNiMjNkNDVhM2VjJlgtQW16LVNpZ25lZEhlYWRlcnM9aG9zdCZhY3Rvcl9pZD0wJmtleV9pZD0wJnJlcG9faWQ9MCJ9.oe0W19SUKo9w-SyeY08LV2bnwsYfxNGgtcnPmrwxQEA)
Gofr is an opinionated microservice development framework. Visit https://gofr.dev for more details and documentation.
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.
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.
- 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}
- 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()
}
- Get all the dependencies using
go get ./...
. It will download gofr along with every other package it requires. - 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