Giter Site home page Giter Site logo

sc-go-templates's Introduction

SC Golang Templates

This repository contains the templates to use the sc CLI tool to generate Golang state machines.

Install sc CLI

go install github.com/SoenkeD/sc

Ensure ~/go/bin is in your path.

Setup

ℹ️ Requirements

A container runtime such as Docker is required.

Install Ginkgo to execute the tests

Getting started

To get started read the guide which goes through the features and intended usage of this tool on an example.

Setup a new project

  1. Navigate to the directory where the project should be created in
  2. Set the desired parameters and execute the command below
sc init --setup https://github.com/SoenkeD/sc-go-templates/main/sc/setup \
	--name myctl \
	--root $PWD/demo  \
	--module demo

See further information for the command here

  1. Navigate into the project
  2. Modify the Print action to print the first argument
  3. Run make run to see the first running state machine

Add to existing code

ℹ️ The directory "{ROOT}/sc" is required to not exist
  1. Navigate to the go root directory in your project (where go.mod is located)
  2. Set the desired parameters and execute the command below
sc init --setup https://github.com/SoenkeD/sc-go-templates/main/sc/add \
	--name myctl \
	--root $PWD/demo  \
	--module demo  \
    --ctl src/controller

Change --ctl to the directory the state machine code should be located. See further information for the command here

  1. Consider adding the Makefile. Then run make sc to generate the code.

  2. To use the generated code access it e.g. by

package main

import (
	"log"

	"demo/src/controller/myctl"
	"demo/src/controller/myctl/controller"
	"demo/src/controller/myctl/state"
)

func main() {
	ctl := myctl.InitCtl(
		&state.Ctx{},
		controller.ControllerSettingsInput{
			AfterInit: &controller.DefaultAfterInitHandler{
				State: state.ExtendedState{
					Hello: "world",
				},
			},
		},
	)

	res, err := ctl.Run()
	if err != nil {
		log.Fatalln(err.PanicErr, err.StateErr)
	}

	log.Println(res)
}

and add to Hello string to ExtendedState in src/controller/myctl/state/ExtendedState.go.

sc-go-templates's People

Contributors

soenked avatar

Stargazers

Oyabun™ avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.