Skip to content

Programatically can be used to manage the life cycle of an application, service or module"

Notifications You must be signed in to change notification settings

faelmori/golife

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

33 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

GoLife Banner

Go Version License Status

Table of Contents

Introduction

GoLife is an innovative system for lifecycle, concurrency, and worker pool management in Go. It enables autonomous process pool handling and can be used via CLI or integrated as a module with an intuitive declarative API. Designed for scalability and execution state control, GoLife simplifies concurrent process management, ensuring efficiency and security.

Key Features

  • Lifecycle Management: Define custom execution stages.
  • Smart Concurrency: Automatically scalable workers.
  • Declarative API: Intuitive process management.
  • Flexible Integration: Usable via CLI or as an embedded module.
  • Event-Driven Hooks: Respond to real-time events.

Usage Example

Lifecycle Management

package main

import (
	"fmt"
	"github.com/faelmori/golife"
)

func main() {
	manager := golife.NewLifecycleManager()

	manager.DefineStage("start").
		OnEnter(func() { fmt.Println("Server started") }).
		OnExit(func() { fmt.Println("Server stopped") })

	manager.DefineStage("processing").
		OnEvent("request", func(data interface{}) {
			fmt.Println("Processing:", data)
		})

	manager.Trigger("processing", "request", "Request 1")
	manager.Trigger("processing", "request", "Request 2")
}

Smart Concurrency

package main

import (
	"fmt"
	"time"
	
	"github.com/faelmori/golife"
)

func main() {
	manager := golife.NewLifecycleManager()

	manager.DefineStage("processing").
		AutoScale(5).
		OnEvent("task", func(data interface{}) {
			fmt.Println("Processing task:", data)
		})

	manager.Trigger("processing", "task", "Task 1")
	manager.Trigger("processing", "task", "Task 2")

	time.Sleep(1 * time.Second) // Wait for workers to process
}

Declarative API

package main

import (
	"fmt"
	
	"github.com/faelmori/golife"
)

func main() {
	manager := golife.NewLifecycleManager()

	manager.DefineStage("start").
		OnEnter(func() { fmt.Println("Server started") }).
		OnExit(func() { fmt.Println("Server stopped") })

	manager.DefineStage("processing").
		AutoScale(3).
		OnEvent("request", func(data interface{}) {
			fmt.Println("Processing:", data)
		})

	manager.Trigger("processing", "request", "Request 1")
	manager.Trigger("processing", "request", "Request 2")
}

Flexible Integration

Using the CLI

# Start the application
golife start --name myApp --cmd "myAppCommand"

# Trigger an event
golife trigger --stage processing --event request --data "Request 1"

# Check the status of the application
golife status

Using as an Embedded Module

package main

import (
	"fmt"
	
	"github.com/faelmori/golife"
)

func main() {
	manager := golife.NewLifecycleManager()

	manager.DefineStage("start").
		OnEnter(func() { fmt.Println("Server started") }).
		OnExit(func() { fmt.Println("Server stopped") })

	manager.DefineStage("processing").
		OnEvent("request", func(data interface{}) {
			fmt.Println("Processing:", data)
		})

	manager.Trigger("processing", "request", "Request 1")
	manager.Trigger("processing", "request", "Request 2")
}

Event-Driven Hooks

package main

import (
	"fmt"
	
	"github.com/faelmori/golife"
)

func main() {
	manager := golife.NewLifecycleManager()

	manager.RegisterEvent("dataReceived", "processing")

	manager.DefineStage("processing").
		OnEvent("dataReceived", func(data interface{}) {
			fmt.Println("Data received:", data)
		})

	manager.Trigger("processing", "dataReceived", "Sample Data")
}

Benefits

  • Optimized Resource Usage: Ensures efficient CPU and memory consumption.
  • Flexible: Can be integrated into various systems.
  • Increased Productivity: Reduces complexity in concurrent process management.

Conclusion

GoLife is designed for developers seeking a robust solution for lifecycle and concurrency management. Whether for distributed systems, application servers, or workflow automation, GoLife brings simplicity and scalability to your infrastructure.

Try it today and streamline concurrent process management in your projects! 🚀

About

Programatically can be used to manage the life cycle of an application, service or module"

Resources

Stars

Watchers

Forks

Packages

No packages published