Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Go SDK support #145

Open
wants to merge 17 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
feat: implements AddArtifactSource function for context
  • Loading branch information
erikreinert committed Mar 2, 2025
commit 8dcb00c46664f600e93e2d77f85ed527f49d878b
32 changes: 31 additions & 1 deletion sdk/go/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,34 @@ module github.com/ALT-F4-LLC/vorpal/sdk/go

go 1.23.5

require google.golang.org/protobuf v1.36.3
require (
github.com/google/uuid v1.6.0
github.com/h2non/filetype v1.1.3
github.com/mholt/archives v0.1.0
google.golang.org/grpc v1.70.0
google.golang.org/protobuf v1.36.3
)

require (
github.com/STARRY-S/zip v0.2.1 // indirect
github.com/andybalholm/brotli v1.1.1 // indirect
github.com/bodgit/plumbing v1.3.0 // indirect
github.com/bodgit/sevenzip v1.6.0 // indirect
github.com/bodgit/windows v1.0.1 // indirect
github.com/dsnet/compress v0.0.2-0.20230904184137-39efe44ab707 // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/hashicorp/go-multierror v1.1.1 // indirect
github.com/hashicorp/golang-lru/v2 v2.0.7 // indirect
github.com/klauspost/compress v1.17.11 // indirect
github.com/klauspost/pgzip v1.2.6 // indirect
github.com/nwaples/rardecode/v2 v2.0.0-beta.4.0.20241112120701-034e449c6e78 // indirect
github.com/pierrec/lz4/v4 v4.1.21 // indirect
github.com/sorairolake/lzip-go v0.3.5 // indirect
github.com/therootcompany/xz v1.0.1 // indirect
github.com/ulikunitz/xz v0.5.12 // indirect
go4.org v0.0.0-20230225012048-214862532bf5 // indirect
golang.org/x/net v0.32.0 // indirect
golang.org/x/sys v0.28.0 // indirect
golang.org/x/text v0.21.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20241202173237-19429a94021a // indirect
)
326 changes: 324 additions & 2 deletions sdk/go/go.sum

Large diffs are not rendered by default.

17 changes: 17 additions & 0 deletions sdk/go/internal/artifact/source.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package artifact

type ArtifactSource struct {
Excludes []string
Hash *string
Includes []string
Path string
}

type ArtifactSourceKind string

const (
ArtifactSourceKind_GIT ArtifactSourceKind = "GIT"
ArtifactSourceKind_HTTP ArtifactSourceKind = "HTTP"
ArtifactSourceKind_LOCAL ArtifactSourceKind = "LOCAL"
ArtifactSourceKind_UNKNOWN ArtifactSourceKind = "UNKNOWN"
)
20 changes: 20 additions & 0 deletions sdk/go/internal/artifact/system.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package artifact

import (
"github.com/ALT-F4-LLC/vorpal/sdk/go/api/v0/artifact"
)

func GetArtifactSystem(system string) artifact.ArtifactSystem {
switch system {
case "aarch64-linux":
return artifact.ArtifactSystem_AARCH64_LINUX
case "aarch64-macos":
return artifact.ArtifactSystem_AARCH64_MACOS
case "x86_64-linux":
return artifact.ArtifactSystem_X86_64_LINUX
case "x86_64-macos":
return artifact.ArtifactSystem_X86_64_MACOS
default:
return artifact.ArtifactSystem_UNKNOWN_SYSTEM
}
}
74 changes: 74 additions & 0 deletions sdk/go/internal/cli/command.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package cli

import (
"flag"
"fmt"
"os"
"runtime"

_artifact "github.com/ALT-F4-LLC/vorpal/sdk/go/api/v0/artifact"
"github.com/ALT-F4-LLC/vorpal/sdk/go/internal/artifact"
)

type startCommand struct {
Level string
Port int
Registry string
Target _artifact.ArtifactSystem
}

func getDefaultSystem() string {
arch := runtime.GOARCH
os := runtime.GOOS

if arch == "arm64" {
arch = "aarch64"
}

if os == "darwin" {
os = "macos"
}

return fmt.Sprintf("%s-%s", arch, os)
}

func NewStartCommand() (*startCommand, error) {
startCmd := flag.NewFlagSet("start", flag.ExitOnError)

startLevel := startCmd.String("level", "INFO", "logging level")
startPort := startCmd.Int("port", 0, "port to listen on")
startRegistry := startCmd.String("registry", "http://localhost:23151", "registry to use")
startTarget := startCmd.String("target", getDefaultSystem(), "target system")

switch os.Args[1] {
case "start":
startCmd.Parse(os.Args[2:])

if *startPort == 0 {
return nil, fmt.Errorf("port is required")
}

if *startRegistry == "" {
return nil, fmt.Errorf("registry is required")
}

if *startTarget == "" {
return nil, fmt.Errorf("target is required")
}

system := artifact.GetArtifactSystem(*startTarget)

if system == _artifact.ArtifactSystem_UNKNOWN_SYSTEM {
return nil, fmt.Errorf("unknown target system")
}

return &startCommand{
Level: *startLevel,
Port: *startPort,
Registry: *startRegistry,
Target: system,
}, nil
default:
return nil, fmt.Errorf("unknown command")
}
}
Loading