initial attempt at building Masonry
This commit is contained in:
26
templates/backend/daemon/daemon.go
Normal file
26
templates/backend/daemon/daemon.go
Normal file
@ -0,0 +1,26 @@
|
||||
package daemon
|
||||
|
||||
type DaemonService interface {
|
||||
Start()
|
||||
Stop()
|
||||
}
|
||||
|
||||
type Daemon struct {
|
||||
services []DaemonService
|
||||
}
|
||||
|
||||
func (d *Daemon) RegisterDaemonServer(service DaemonService) {
|
||||
d.services = append(d.services, service)
|
||||
}
|
||||
|
||||
func (d *Daemon) Start() {
|
||||
for _, service := range d.services {
|
||||
go service.Start()
|
||||
}
|
||||
}
|
||||
|
||||
func (d *Daemon) Stop() {
|
||||
for _, service := range d.services {
|
||||
service.Stop()
|
||||
}
|
||||
}
|
3
templates/backend/daemon/readme.md
Normal file
3
templates/backend/daemon/readme.md
Normal file
@ -0,0 +1,3 @@
|
||||
# Daemon
|
||||
|
||||
A library that provides a way to register and start multiple long-running services with safe tear-down when they are done.
|
5
templates/backend/main.go
Normal file
5
templates/backend/main.go
Normal file
@ -0,0 +1,5 @@
|
||||
package main
|
||||
|
||||
func main() {
|
||||
|
||||
}
|
38
templates/cli/cli.go
Normal file
38
templates/cli/cli.go
Normal file
@ -0,0 +1,38 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/urfave/cli/v2"
|
||||
"os"
|
||||
"time"
|
||||
)
|
||||
|
||||
func main() {
|
||||
commands := []*cli.Command{
|
||||
exampleCmd(),
|
||||
// call your command functions from the commands.go file
|
||||
}
|
||||
|
||||
app := &cli.App{
|
||||
Name: "ExampleApp",
|
||||
Usage: "An example CLI tool",
|
||||
Version: "v1.0.0",
|
||||
Description: "This is an example CLI tool",
|
||||
Commands: commands,
|
||||
Flags: nil,
|
||||
Authors: []*cli.Author{
|
||||
{
|
||||
Name: "Mason Payne", // Update this to your name
|
||||
Email: "mason@masonitestudios.com", // Update this to your email
|
||||
},
|
||||
},
|
||||
Copyright: fmt.Sprintf("%d Example Corp", time.Now().Year()),
|
||||
UseShortOptionHandling: true,
|
||||
}
|
||||
|
||||
err := app.Run(os.Args)
|
||||
if err != nil {
|
||||
fmt.Println(fmt.Errorf("error running app | %w", err))
|
||||
return
|
||||
}
|
||||
}
|
20
templates/cli/commands.go
Normal file
20
templates/cli/commands.go
Normal file
@ -0,0 +1,20 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/urfave/cli/v2"
|
||||
)
|
||||
|
||||
func exampleCmd() *cli.Command {
|
||||
return &cli.Command{
|
||||
Name: "example",
|
||||
Aliases: []string{"e"},
|
||||
Usage: "Run an example command",
|
||||
Action: func(c *cli.Context) error {
|
||||
fmt.Println("This is an example command")
|
||||
return nil
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
// add commands here
|
Reference in New Issue
Block a user