Files
CrimsonandGitHub 538a2d0de2 chore: Refactor models and other shareable packages into importable pkg (#762)
* Move models and other shareable code to pkg/domain and add own go.mod

* Update all references to use pkg/domain paths

* Fix generated file

* Ensure pkg/domain tests are run by just tests

* Use new models path in connector templates

* Copy local pkg/domain in dockerfile

* Ensure pkg/domain is subject to go generate
2026-06-23 13:08:32 +00:00

52 lines
986 B
Go

package models
import (
"encoding/json"
)
type State struct {
ID StateID
ConnectorID ConnectorID
State json.RawMessage
}
func (s State) MarshalJSON() ([]byte, error) {
return json.Marshal(&struct {
ID string `json:"id"`
ConnectorID string `json:"connectorID"`
State json.RawMessage `json:"state"`
}{
ID: s.ID.String(),
ConnectorID: s.ConnectorID.String(),
State: s.State,
})
}
func (s *State) UnmarshalJSON(data []byte) error {
var aux struct {
ID string `json:"id"`
ConnectorID string `json:"connectorID"`
State json.RawMessage `json:"state"`
}
if err := json.Unmarshal(data, &aux); err != nil {
return err
}
id, err := StateIDFromString(aux.ID)
if err != nil {
return err
}
connectorID, err := ConnectorIDFromString(aux.ConnectorID)
if err != nil {
return err
}
s.ID = *id
s.ConnectorID = connectorID
s.State = aux.State
return nil
}