mirror of
https://github.com/hanzo-fi/payments.git
synced 2026-10-30 20:31:20 +00:00
- go.mod module path + all self-imports: github.com/formancehq/payments -> github.com/hanzo-fi/payments (1590 .go files / 3152 refs; 20 modules: root, pkg/client, pkg/domain, 18 ce/plugins). External dep kept: formancehq/go-libs. - plugins: each ce/plugins/* consumed a *published* pkg/domain; added local 'replace .../pkg/domain => ../../../pkg/domain' (consistent with root) so every standalone plugin module builds in-monorepo. compile-plugin.sh MOD var rebranded too. - branding: README, LICENSE (dual MIT+EE; upstream copyright retained + Hanzo added), goreleaser (release images -> registry.hanzo.ai/hanzo-fi, OCI labels, homepage), proto go_package, renovate, speakeasy gen.yaml, connector-template *.gotpl. - CI: removed Numary/Formance workflows + composite action; added canonical hanzo.yml + cicd.yml (hanzoai/ci, gated HANZO_CI_ENABLED) + secretless ci.yml (go build/vet). - kept as data/compat keys: wire capability enums ALLOW_FORMANCE_*, generated SDK type client.Formance, domain field FormanceRedirectURL, OTEL_SERVICE_NAME, upstream base image. - verified: go build ./... (default + -tags ee) + all 20 nested modules green.
109 lines
2.6 KiB
Go
109 lines
2.6 KiB
Go
package main
|
|
|
|
import (
|
|
"context"
|
|
"flag"
|
|
"fmt"
|
|
"log"
|
|
"os"
|
|
"path/filepath"
|
|
"regexp"
|
|
"strings"
|
|
)
|
|
|
|
const repoModule = "github.com/hanzo-fi/payments"
|
|
|
|
var (
|
|
connectorDirPath = flag.String("connector-dir-path", "", "Path where to create the new connector directory")
|
|
connectorName = flag.String("connector-name", "", "Name of the new connector")
|
|
|
|
packageNameRegex = regexp.MustCompile(`^[a-z][a-z0-9_]*$`)
|
|
)
|
|
|
|
func main() {
|
|
flag.Parse()
|
|
|
|
if *connectorDirPath == "" {
|
|
log.Fatal("connector-dir-path flag is required")
|
|
}
|
|
|
|
if *connectorName == "" {
|
|
log.Fatal("connector-name flag is required")
|
|
}
|
|
|
|
if !isValidPackageName(*connectorName) {
|
|
log.Fatalf("connector-name %q contains invalid characters: must be a valid package name", *connectorName)
|
|
}
|
|
|
|
connectorPath := filepath.Join(*connectorDirPath, *connectorName)
|
|
|
|
absDir, err := filepath.Abs(*connectorDirPath)
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
// connector-dir-path is always <repo-root>/{ce,ee}/plugins, so repo root is two levels up.
|
|
repoRoot := filepath.Dir(filepath.Dir(absDir))
|
|
|
|
pluginAbs := filepath.Join(absDir, *connectorName)
|
|
|
|
relFromRoot, err := filepath.Rel(repoRoot, pluginAbs)
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
relSlash := filepath.ToSlash(relFromRoot)
|
|
modulePath := repoModule + "/" + relSlash
|
|
|
|
// EE plugins live inside the root module; only CE plugins get their own go.mod.
|
|
isCE := strings.HasPrefix(relSlash, "ce/plugins/")
|
|
|
|
// Create the new connector's directory
|
|
if err := os.Mkdir(connectorPath, 0755); err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
|
|
// Create the new connector client's directory
|
|
if err := os.Mkdir(filepath.Join(connectorPath, "client"), 0755); err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
|
|
goVersion, err := goVersionFromFlake(repoRoot)
|
|
if err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
|
|
// Create the new connector's files
|
|
if err := createFiles(
|
|
context.Background(),
|
|
connectorPath,
|
|
isCE,
|
|
map[string]interface{}{
|
|
"Connector": *connectorName,
|
|
"Module": modulePath,
|
|
"GoVersion": goVersion,
|
|
},
|
|
); err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
}
|
|
|
|
func isValidPackageName(name string) bool {
|
|
if name == "go" || name == "main" || name == "internal" {
|
|
return false
|
|
}
|
|
return packageNameRegex.MatchString(name)
|
|
}
|
|
|
|
var goVersionRegex = regexp.MustCompile(`\bgo_1_(\d+)\b`)
|
|
|
|
func goVersionFromFlake(repoRoot string) (string, error) {
|
|
data, err := os.ReadFile(filepath.Join(repoRoot, "flake.nix"))
|
|
if err != nil {
|
|
return "", fmt.Errorf("reading flake.nix: %w", err)
|
|
}
|
|
m := goVersionRegex.FindSubmatch(data)
|
|
if m == nil {
|
|
return "", fmt.Errorf("no go_1_XX package found in flake.nix")
|
|
}
|
|
return "1." + string(m[1]), nil
|
|
}
|