Categorygithub.com/davfer/goforarun
modulepackage
0.0.9
Repository: https://github.com/davfer/goforarun.git
Documentation: pkg.go.dev

# README

GoForARun

Simple package to help bootstrapping projects.

Features

  • Run a service easily, just need to have an Init(), Run(), and Shutdown() methods.
  • Configuration via config.yaml file to configure your service.
  • Build info with version, commit, and date. (GoReleaser friendly)
  • Observability with OpenTelemetry.
  • Provided with HTTP and GRPC servers. (see /examples)

Getting started

Run to create a project:

$ go run github.com/davfer/goforarun/cmd/[email protected] <project_name>
$ cd <project_name>
$ go mod init <project_name>
$ go get github.com/davfer/goforarun
$ go run .

Use the package directly:

go get github.com/davfer/goforarun

Usage

Your application will need to implement the App interface, like:

// config.go
type ExampleConfig struct {
    FrameworkConfig *app.BaseAppConfig `yaml:"framework"` 
    // Extend your config here
}

func (c *ExampleConfig) Framework() *app.BaseAppConfig {
    return c.FrameworkConfig
}

// service.go
type ExampleService struct {
	cfg *ExampleConfig
	// Add your dependencies here
}

func (e *ExampleService) Init(cfg *ExampleConfig) ([]app.RunnableServer, error) {
	e.cfg = cfg
	// Add your servers and also initialize your dependencies here
	return []app.RunnableServer{}, nil
}

func (e *ExampleService) Run(ctx context.Context) error {
	// Run your application here if needed
	fmt.Printf("Hello, %s!\n", e.cfg.Framework().ServiceName)

	return nil
}

func (e *ExampleService) Shutdown(ctx context.Context) error {
	// Shutdown your application here if needed, no need to shut down your servers
	return nil
}

Then, create a main.go file like:

// main.go
var (
	version = "dev"
	commit  = "none"
	date    = "unknown"
)

func main() {
	build := &app.BuildInfo{Version: version, Commit: commit, Date: date}
	if svc, err := app.NewService[*ExampleService, *ExampleConfig](&ExampleService{}, build); err != nil {
		panic(err)
	} else {
		svc.Run(context.Background())
	}
}

# Packages

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
No description provided by the author

# Functions

NewConfig creates a new configuration from a file path.
NewService creates a new service with the given app and config.

# Constants

No description provided by the author

# Variables

No description provided by the author

# Structs

BaseAppConfig is the base configuration for the service, it needs a name, a log level, a log format, and an observability mode.
No description provided by the author
BuildInfo is the information of the build, it contains the version, the commit and the date.
InfoServer contains the information of a server to be started.
No description provided by the author
No description provided by the author

# Interfaces

No description provided by the author
No description provided by the author
No description provided by the author