Added models
This commit is contained in:
2
go.mod
2
go.mod
@@ -1,3 +1,3 @@
|
|||||||
module atos-terraform-registry
|
module git.systemact.nl/henk/mars-terraform-registry
|
||||||
|
|
||||||
go 1.26.2
|
go 1.26.2
|
||||||
|
|||||||
97
internal/model/models.go
Normal file
97
internal/model/models.go
Normal file
@@ -0,0 +1,97 @@
|
|||||||
|
package model
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
)
|
||||||
|
|
||||||
|
type ProviderPlatformOs int
|
||||||
|
type ProviderPlatformArch int
|
||||||
|
|
||||||
|
const (
|
||||||
|
OsDarwin ProviderPlatformOs = iota
|
||||||
|
OsLinux
|
||||||
|
OsWindows
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
osName = map[ProviderPlatformOs]string{
|
||||||
|
OsDarwin: "darwin",
|
||||||
|
OsLinux: "linux",
|
||||||
|
OsWindows: "windows",
|
||||||
|
}
|
||||||
|
|
||||||
|
osFromName = map[string]ProviderPlatformOs{
|
||||||
|
"darwin": OsDarwin,
|
||||||
|
"linux": OsLinux,
|
||||||
|
"windows": OsWindows,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
func (os ProviderPlatformOs) String() string {
|
||||||
|
return osName[os]
|
||||||
|
}
|
||||||
|
|
||||||
|
const (
|
||||||
|
ArchAmd64 ProviderPlatformArch = iota
|
||||||
|
ArchArm64
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
archName = map[ProviderPlatformArch]string{
|
||||||
|
ArchAmd64: "amd64",
|
||||||
|
ArchArm64: "arm",
|
||||||
|
}
|
||||||
|
|
||||||
|
archFromName = map[string]ProviderPlatformArch{
|
||||||
|
"amd64": ArchAmd64,
|
||||||
|
"arm": ArchArm64,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
func (arch ProviderPlatformArch) String() string {
|
||||||
|
return archName[arch]
|
||||||
|
}
|
||||||
|
|
||||||
|
type ProviderPlatform struct {
|
||||||
|
Os ProviderPlatformOs
|
||||||
|
Arch ProviderPlatformArch
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p ProviderPlatform) MarshalJSON() ([]byte, error) {
|
||||||
|
return json.Marshal(struct {
|
||||||
|
Os string `json:"os"`
|
||||||
|
Arch string `json:"arch"`
|
||||||
|
}{
|
||||||
|
Os: p.Os.String(),
|
||||||
|
Arch: p.Arch.String(),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *ProviderPlatform) UnmarshalJSON(data []byte) error {
|
||||||
|
var temp struct {
|
||||||
|
Os string `json:"os"`
|
||||||
|
Arch string `json:"arch"`
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := json.Unmarshal(data, &temp); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
var ok bool
|
||||||
|
if p.Os, ok = osFromName[temp.Os]; !ok {
|
||||||
|
return fmt.Errorf("unknown OS: %s", temp.Os)
|
||||||
|
}
|
||||||
|
|
||||||
|
if p.Arch, ok = archFromName[temp.Arch]; !ok {
|
||||||
|
return fmt.Errorf("unknown architecture: %s", temp.Arch)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
type ProviderVersion struct {
|
||||||
|
Version string `json:"version"`
|
||||||
|
Protocols []string `json:"protocols"`
|
||||||
|
Platforms []ProviderPlatform `json:"platforms"`
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user