Create an application
For running a simple gosoline application we use the following 3 files:
module.go
→ kernel module with business logicconfig.dist.yml
→ base configuration filemain.go
→ setup and run the application
Create the kernel module
The kernel module contains the actual application logic. The HelloWorldModule
struct has to implement the
kernel.Module
interface. The func NewHelloWorldModule
is of the type kernel.ModuleFactory
and is used to add
the module to the application.
module.go
package main
import (
"context"
"github.com/justtrackio/gosoline/pkg/cfg"
"github.com/justtrackio/gosoline/pkg/kernel"
"github.com/justtrackio/gosoline/pkg/log"
)
func NewHelloWorldModule(ctx context.Context, config cfg.Config, logger log.Logger) (kernel.Module, error) {
return &HelloWorldModule{
logger: logger.WithChannel("hello-world"),
}, nil
}
type HelloWorldModule struct {
logger log.Logger
}
func (h HelloWorldModule) Run(ctx context.Context) error {
h.logger.Info("Hello World")
return nil
}
Create the main file
In the main function, we're running the application by adding the HelloWorldModule
to the kernel via the
NewHelloWorldModule
factory.
main.go
package main
import "github.com/justtrackio/gosoline/pkg/application"
func main() {
application.Run(
application.WithModuleFactory("hello-world", NewHelloWorldModule),
)
}
Create the config file
The last missing piece for a minimal gosoline application is the default config file which is distributed with the application. For a minimal version it has at least the application identifiers and enviroment value.
config.dist.yml
env: dev
app_project: gosoline
app_family: get-started
app_group: grp
app_name: hello-world
Application output
Running the application will result in the following output:
stdout
08:43:03.536 main info applied priority 1 config post processor 'gosoline.dx.autoCreate' application: hello-world, group: grp
08:43:03.536 main info applied priority 1 config post processor 'gosoline.dx.useRandomPort' application: hello-world, group: grp
08:43:03.536 main info applied priority 8 config post processor 'gosoline.log.handler_main' application: hello-world, group: grp
07:43:03.537 kernel info starting kernel application: hello-world, group: grp
07:43:03.537 kernel info cfg api.health.path=/health application: hello-world, group: grp
07:43:03.537 kernel info cfg api.health.port=0 application: hello-world, group: grp
07:43:03.537 kernel info cfg app_family=get-started application: hello-world, group: grp
07:43:03.537 kernel info cfg app_group=grp application: hello-world, group: grp
07:43:03.537 kernel info cfg app_name=hello-world application: hello-world, group: grp
07:43:03.537 kernel info cfg app_project=gosoline application: hello-world, group: grp
07:43:03.537 kernel info cfg appctx.metadata.server.port=0 application: hello-world, group: grp
07:43:03.537 kernel info cfg dx.auto_create=true application: hello-world, group: grp
07:43:03.537 kernel info cfg dx.use_random_port=true application: hello-world, group: grp
07:43:03.537 kernel info cfg env=dev application: hello-world, group: grp
07:43:03.537 kernel info cfg kernel.health_check.timeout=1m0s application: hello-world, group: grp
07:43:03.537 kernel info cfg kernel.health_check.wait_interval=3s application: hello-world, group: grp
07:43:03.537 kernel info cfg kernel.kill_timeout=10s application: hello-world, group: grp
07:43:03.537 kernel info cfg log.handlers.main.formatter=console application: hello-world, group: grp
07:43:03.537 kernel info cfg log.handlers.main.level=info application: hello-world, group: grp
07:43:03.537 kernel info cfg log.handlers.main.timestamp_format=15:04:05.000 application: hello-world, group: grp
07:43:03.537 kernel info cfg log.handlers.main.type=iowriter application: hello-world, group: grp
07:43:03.537 kernel info cfg log.handlers.main.writer=stdout application: hello-world, group: grp
07:43:03.537 kernel info cfg metric.application={app_name} application: hello-world, group: grp
07:43:03.537 kernel info cfg metric.cloudwatch.naming.pattern={project}/{env}/{family}/{group}-{app} application: hello-world, group: grp
07:43:03.537 kernel info cfg metric.enabled=false application: hello-world, group: grp
07:43:03.537 kernel info cfg metric.environment={env} application: hello-world, group: grp
07:43:03.537 kernel info cfg metric.family={app_family} application: hello-world, group: grp
07:43:03.537 kernel info cfg metric.group={app_group} application: hello-world, group: grp
07:43:03.537 kernel info cfg metric.interval=1m0s application: hello-world, group: grp
07:43:03.537 kernel info cfg metric.project={app_project} application: hello-world, group: grp
07:43:03.537 kernel info cfg metric.writer= application: hello-world, group: grp
07:43:03.537 kernel info cfg fingerprint: f673796f9852c4b7e669201638f06f60 application: hello-world, group: grp
07:43:03.537 kernel info stage 0 up and running with 1 modules application: hello-world, group: grp
07:43:03.538 kernel info running background module metric in stage 0 application: hello-world, group: grp
07:43:03.538 kernel info stage 1024 up and running with 2 modules application: hello-world, group: grp
07:43:03.538 kernel info stage 2048 up and running with 1 modules application: hello-world, group: grp
07:43:03.538 kernel info kernel up and running application: hello-world, group: grp
07:43:03.538 kernel info running background module api-health-check in stage 1024 application: hello-world, group: grp
07:43:03.538 metrics info metrics not enabled.. application: hello-world, group: grp
07:43:03.538 kernel info running background module metadata-server in stage 1024 application: hello-world, group: grp
07:43:03.538 kernel info stopped background module metric application: hello-world, group: grp
07:43:03.538 kernel info running foreground module hello-world in stage 2048 application: hello-world, group: grp
07:43:03.538 hello-world info Hello World application: hello-world, group: grp
07:43:03.538 kernel info stopped foreground module hello-world application: hello-world, group: grp
07:43:03.538 kernel info stopping kernel due to: no more foreground modules in running state application: hello-world, group: grp
07:43:03.538 kernel info stopping stage 2048 application: hello-world, group: grp
07:43:03.538 kernel info stopped stage 2048 application: hello-world, group: grp
07:43:03.538 kernel info stopping stage 1024 application: hello-world, group: grp
07:43:03.538 kernel info stopped background module api-health-check application: hello-world, group: grp
07:43:03.538 metadata-server info serving metadata on address [::]:45745 application: hello-world, group: grp
07:43:03.538 kernel info stopped background module metadata-server application: hello-world, group: grp
07:43:03.538 kernel info stopped stage 1024 application: hello-world, group: grp
07:43:03.538 kernel info stopping stage 0 application: hello-world, group: grp
07:43:03.538 kernel info stopped stage 0 application: hello-world, group: grp
07:43:03.538 kernel info leaving kernel with exit code 0 application: hello-world, group: grp