ametory-erp-modules

module
v1.0.68 Latest Latest
Warning

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

Go to latest
Published: Aug 22, 2025 License: MIT

README

ametory-erp-modules

EXAMPLE INIT CODE

package main

import (
	"ametory-erp/api/router"
	"ametory-erp/config"
	"context"
	"fmt"
	"log"
	"net/http"

	"github.com/AMETORY/ametory-erp-modules/app"
	"github.com/gin-gonic/gin"
	"github.com/spf13/cobra"
)

func init() {

	rootCmd := &cobra.Command{
		Use:   "app",
		Short: "Application CLI",
	}

	migrateCmd := &cobra.Command{
		Use:   "migrate",
		Short: "Run database migrations",
		Run: func(cmd *cobra.Command, args []string) {
			fmt.Println("Running migrations...")
			// Add migration logic here
			initContainer(false)
		},
	}

	serveCmd := &cobra.Command{
		Use:   "serve",
		Short: "Start the application server",
		Run: func(cmd *cobra.Command, args []string) {
			fmt.Println("Starting server...")
			appContainer := initContainer(true)

			r := gin.Default()

			r.GET("/", func(c *gin.Context) {
				c.JSON(http.StatusOK, gin.H{
					"message": "Hello, World!",
				})
			})

			v1 := r.Group("/api/v1")
			router.SetUpAuthRoutes(v1, appContainer)

			r.Run(":" + config.App.Server.Port)
		},
	}

	rootCmd.AddCommand(migrateCmd, serveCmd)

	if err := rootCmd.Execute(); err != nil {
		log.Fatalf("Error executing command, %s", err)
	}
}

func initContainer(skipMigrate bool) *app.AppContainer {
	ctx := context.Background()
	cfg, err := config.LoadConfig()
	if err != nil {
		log.Fatalf("Failed to load config: %v", err)
	}

	db, err := config.InitDB(cfg)
	if err != nil {
		log.Fatalf("Failed to connect to database: %v", err)
	}

	fmt.Println("Successfully connected to database", cfg.Database.Name)

	return app.NewAppContainer(
		db,
		nil,
		&ctx,
		skipMigrate,
		cfg.Server.BaseURL,
		app.WithAdminAuth(),
		app.WithHRIS(),
	)
}

See all code in example folder

run server with

go run main.go serve

run migrate with

go run main.go migrate
Use CLI Generator
go install github.com/AMETORY/ametory-erp-modules/cmd/erpgen@latest
DEMO

https://github.com/user-attachments/assets/bde4f52e-efe8-45bf-a343-8e8637145ea6

Directories

Path Synopsis
app
cmd
erpgen command
shipping/provider
distribution/shipping/provider/gosend.go
distribution/shipping/provider/gosend.go
tax
internal
bom
pos
kpi
fin
Package fin is a library containing a collection of financial functions for time value of money (annuities), cash flow, interest rate conversions, bonds and depreciation calculations.
Package fin is a library containing a collection of financial functions for time value of money (annuities), cash flow, interest rate conversions, bonds and depreciation calculations.

Jump to

Keyboard shortcuts

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