happy

package module
v0.28.3 Latest Latest
Warning

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

Go to latest
Published: Feb 22, 2025 License: Apache-2.0 Imports: 17 Imported by: 6

README

Happy Logo

Happy Prototyping Framework and SDK

Package happy is a powerful tool for developers looking to bring their ideas to life through rapid prototyping. With its comprehensive set of resources and modular design, it's easy to create working prototypes or MVPs with minimal technical knowledge or infrastructure planning. Plus, its flexible design allows it to seamlessly integrate into projects with components written in different programming languages. So why wait? Let Happy help you achieve your goals and bring a smile to your face along the way.

Happy is very early in development phase and is not intended for production use.

GitHub Release PkgGoDev Coverage Status GitHub License

Creating application

Happy SDK is designed to simplify your development process without introducing any new or additional developer tools. Your applications built with Happy can be used, built, and tested with the standard Go build tools, such as 'go test', 'go build', and 'go run'. With Happy, you have complete control over your development environment, as it will not add any third-party dependencies to your project.

Here's a simple example of how you can use Happy:

// main.go
package main

import (
	"fmt"

	"github.com/happy-sdk/happy"
	"github.com/happy-sdk/happy/sdk/action"
	"github.com/happy-sdk/happy/sdk/app/session"
)

func main() {
  app := happy.New(happy.Settings{})

  app.Do(func(sess *session.Context, args action.Args) error {
    sess.Log().Println("Hello, world!")
    return nil
  })

  app.Run()
}

For more examples, take a look at the examples section and the examples in the ./examples/ directory."

Application api

More details of api read happy Godoc
PkgGoDev


...
app.AddInfo(/* add paragraph to app help */)
app.WithOptions(/* adds allowed runtime option */)
app.SetOptions(/* update default value for any application or addon option */) 
app.Setup(/* optional setup action called only first time app is used */)
app.WithAddon(/* adds addon to app */)
app.WithBrand(/* customize branding of the app */)
app.WithCommands(/* adds command(s) to app */)
app.WithFlags(/* adds flag(s) to app root command */)
app.WithLogger(/* uses provided logger */)
app.WithMigrations(/* use migration manager */)
app.WithServices(/* adds service(s) to app */)

...

...
// Application root command actions
app.BeforeAlways(/* called always before any command is invoked*/)
app.Before(/* called before root command is invoked*/)
app.Do(/* root command Do function */)
app.AfterSuccess(/* called when root cmd or sub command returns without errors */)
app.AfterFailure(/* called when root cmd or sub command returns with errors */)
app.AfterAlways(/* called always when root cmd or sub command returns */)
app.Tick(/* called in specific interfal while root command is blocking */)
app.Tock(/* called after every tick*/)
...
Commands

command.Command provides a universal API for attaching sub-commands directly to the application or providing them from an Addon.
PkgGoDev

import "github.com/happy-sdk/happy/sdk/cli/command"
...
cmd := command.New(command.Config{
  Name: "my-command"
})

cmd.Do(/* Main function for the command */)
// Optional:
cmd.Before(/* Called after app.Before and before cmd.Do */)
cmd.AfterSuccess(/* Called when cmd.Do returns without errors */)
cmd.AfterFailure(/* Called when cmd.Do returns with errors */)
cmd.AfterAlways(/* Called always when cmd.Do returns */)

cmd.Usage(/* add attitional usage lines to help menu */)
cmd.AddInfo(/* add long description paragraph for command */)
cmd.WithSubCommands(/* Add a sub-command to the command */)
cmd.WithFlags(/* add flag(s) to  command*/)
...
Services

The services.Service API provides a flexible way to add runtime-controllable background services to your application.
PkgGoDev

import (
  "github.com/happy-sdk/happy/sdk/services"
  "github.com/happy-sdk/happy/sdk/services/service"
)
...
svc := services.New(service.Config{
  Name: "my-service",
})

svc.OnRegister(/* Called when the app starts. */)
svc.OnStart(/* Called when the service is requested to start. */)
svc.OnStop(/* Called when the service is requested to stop. */)
svc.OnEvent(/* Called when a specific event is received. */)
svc.OnAnyEvent(/* Called when any event is received. */)
svc.Cron(/* Scheduled cron jobs to run when the service is running. */)
svc.Tick(/* Called every tick when the service is running. */)
svc.Tock(/* Called after every tick when the service is running. */)

app.WithServices(svc)
...

Addons

Addons provide a simple way to bundle commands and services into a single Go package, allowing for easy sharing between projects.
PkgGoDev

// main.go
package main

import (
  "github.com/happy-sdk/happy"
  "helloworld"
)

func main() {
  app := happy.New(happy.Settings{})
  app.WithAddons(helloworld.Addon())
  app.Main()
}

// helloworld/addon.go
package helloworld

import (
  "github.com/happy-sdk/happy/sdk/addon"
  "github.com/happy-sdk/happy/sdk/custom"
)

type HelloWorldAPI struct {
  custom.API
}

func Addon() *happy.Addon {
  addon := addon.New(addon.Config{
    Name: "Releaser",
  }, 
    addon.Option("my-opt", "default-val", "custom option", false, nil),
  )


  // Optional: Register commands provided by the addon
  addon.ProvidesCommands(/* provide command(s) */)

  // Optional: Register services provided by the addon
  addon.ProvidesServices(/* provide service(s) */)

  // Optional: Make a custom API accessible across the application 
  addon.ProvideAPI(&HelloWorldAPI{}) 

  // Register all events that the addon may emit ()
  addon.Emits(/* events what addon emits */)

  // Optional callback to be called when the addon is registered
  addon.OnRegister(func(sess *happy.Session, opts *happy.Options) error {
    sess.Log().Notice("hello-world addon registered")
    return nil
  })

  return addon
}

Credits

GitHub contributors

Happy banner design.
Happy banner was designed by Egon Elbre egonelbre.com

Documentation

Overview

Package happy provides a modular framework for rapid prototyping in Go. With this SDK, developers of all levels can easily bring their ideas to life. Whether you're a hacker or a creator, Package happy has everything you need to tackle your domain problems and create working prototypes or MVPs with minimal technical knowledge and infrastructure planning.

Its modular design enables you to package your commands and services into reusable addons, so you're not locked into any vendor tools. It also fits well into projects where different components are written in different programming languages.

Let Package happy help you bring your projects from concept to reality and make you happy along the way.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func API

func API[API custom.API](sess *session.Context, addonSlug string) (api API, err error)

API returns the API for the given addon slug if addon has given API registered.

func New

func New(s Settings) *app.Main
Example
package main

import (
	"fmt"

	"github.com/happy-sdk/happy"
	"github.com/happy-sdk/happy/sdk/action"
	"github.com/happy-sdk/happy/sdk/app/session"
	"github.com/happy-sdk/happy/sdk/logging"
)

func main() {
	app := happy.New(happy.Settings{})

	// Create a new test logger
	log := logging.NewTestLogger(logging.LevelError)
	app.WithLogger(log)

	app.Do(func(sess *session.Context, args action.Args) error {
		sess.Log().Println("Hello, world!")
		return nil
	})

	app.Run()
	fmt.Println(log.Output())
}
Output:

{"level":"out","msg":"Hello, world!"}

Types

type Settings added in v0.11.0

type Settings struct {
	// Appication info
	Name           settings.String `key:"app.name" default:"Happy Prototype" desc:"Application name"`
	Slug           settings.String `key:"app.slug" default:"" desc:"Application slug"`
	Identifier     settings.String `key:"app.identifier" desc:"Application identifier"`
	Description    settings.String `` /* 156-byte string literal not displayed */
	CopyrightBy    settings.String `key:"app.copyright_by" default:"Anonymous" desc:"Application author"`
	CopyrightSince settings.Uint   `key:"app.copyright_since" default:"0" desc:"Application copyright since"`
	License        settings.String `key:"app.license" default:"NOASSERTION" desc:"Application license"`

	// Application settings
	Engine   engine.Settings   `key:"app.engine"`
	CLI      cli.Settings      `key:"app.cli"`
	Config   config.Settings   `key:"app.config"`
	DateTime datetime.Settings `key:"app.datetime"`
	Instance instance.Settings `key:"app.instance"`
	Logging  logging.Settings  `key:"app.logging"`
	Services services.Settings `key:"app.services"`
	Stats    stats.Settings    `key:"app.stats"`

	Devel devel.Settings `key:"app.devel"`
	// contains filtered or unexported fields
}

func (Settings) Blueprint added in v0.11.0

func (s Settings) Blueprint() (*settings.Blueprint, error)

Blueprint returns a blueprint for the settings.

func (*Settings) Extend added in v0.11.0

func (s *Settings) Extend(ss settings.Settings)

Extend adds a new settings group to the application settings.

func (*Settings) Migrate added in v0.15.0

func (s *Settings) Migrate(keyfrom, keyto string)

Migrate allows auto migrate old settigns from keyfrom to keyto when applying preferences from deprecated keyfrom.

Directories

Path Synopsis
addons
cmd
hap module
internal
cmd/hap module
pkg
bitutils module
branding module
bytesize module
cli/ansicolor module
devel/goutils module
fsutils module
i18n module
logging module
networking module
options module
settings module
strings/bexp module
strings/slug module
tui module
vars module
version module
sdk
app
cli
Package cli provides utilities for happy command line interfaces.
Package cli provides utilities for happy command line interfaces.
networking/address
Package address provides functions for working with "happy" addresses, which are URL-like strings that define the location of a resource in the "happy" system.
Package address provides functions for working with "happy" addresses, which are URL-like strings that define the location of a resource in the "happy" system.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL