Skip to content

Commit

Permalink
Add version to the Service struct
Browse files Browse the repository at this point in the history
  • Loading branch information
quentinguidee committed Sep 18, 2023
1 parent 3f19a76 commit aa3f400
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 5 deletions.
3 changes: 3 additions & 0 deletions .run/Run Vertex.run.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
<configuration default="false" name="Run Vertex" type="GoApplicationRunConfiguration" factoryName="Go Application">
<module name="Vertex" />
<working_directory value="$PROJECT_DIR$" />
<envs>
<env name="DEBUG" value="1" />
</envs>
<kind value="PACKAGE" />
<package value="github.com/vertex-center/vertex" />
<directory value="$PROJECT_DIR$" />
Expand Down
51 changes: 46 additions & 5 deletions types/service.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,30 @@
package types

import "errors"
import (
"errors"

"github.com/vertex-center/vertex/pkg/log"
"github.com/vertex-center/vlog"
)

const (
URLKindClient = "client"
)

var (
ErrServiceNotFound = errors.New("the service was not found")
)

type Version int

type ServiceVersioning struct {
// Version is the version of the service format used.
Version Version `yaml:"version" json:"version"`
}

type Service struct {
ServiceVersioning

// ID is the identifier of the service. It must be unique.
ID string `yaml:"id" json:"id"`

Expand Down Expand Up @@ -41,6 +59,33 @@ type Service struct {
Methods ServiceMethods `yaml:"methods" json:"methods"`
}

type ServiceV1 Service

func (s *Service) UnmarshalYAML(unmarshal func(interface{}) error) error {
var versioning ServiceVersioning
err := unmarshal(&versioning)
if err != nil {
return err
}
s.ServiceVersioning = versioning

log.Debug("reading service", vlog.Int("version", int(versioning.Version)))

switch versioning.Version {
case 0, 1:
var service ServiceV1
err := unmarshal(&service)
if err != nil {
return err
}
*s = Service(service)
default:
return errors.New("service version not supported")
}

return nil
}

type DatabaseEnvironment struct {
// DisplayName is a readable name for the user.
DisplayName string `yaml:"display_name" json:"display_name"`
Expand Down Expand Up @@ -187,10 +232,6 @@ type URL struct {
Kind string `yaml:"kind" json:"kind"`
}

var (
ErrServiceNotFound = errors.New("the service was not found")
)

type ServiceAdapterPort interface {
// Get a service with its id. Returns ErrServiceNotFound if
// the service was not found.
Expand Down

0 comments on commit aa3f400

Please sign in to comment.