Changed Header to return a non-pointer, and removed extension type from GetCtx generic

gql_cataclysm
noah metz 2023-09-18 21:43:39 -06:00
parent ff7046badf
commit d86d424cd7
2 changed files with 6 additions and 32 deletions

@ -508,7 +508,7 @@ func (node *Node) Process(ctx *Context, source NodeID, signal Signal) error {
return ctx.Send(messages) return ctx.Send(messages)
} }
func GetCtx[T Extension, C any](ctx *Context, ext_type ExtType) (C, error) { func GetCtx[C any](ctx *Context, ext_type ExtType) (C, error) {
var zero_ctx C var zero_ctx C
ext_info, ok := ctx.Extensions[ext_type] ext_info, ok := ctx.Extensions[ext_type]
if ok == false { if ok == false {

@ -20,8 +20,12 @@ type SignalHeader struct {
ReqID uuid.UUID `gv:"req_id"` ReqID uuid.UUID `gv:"req_id"`
} }
func (header SignalHeader) Header() SignalHeader {
return header
}
type Signal interface { type Signal interface {
Header() *SignalHeader Header() SignalHeader
Permission() Tree Permission() Tree
} }
@ -95,9 +99,6 @@ type CreateSignal struct {
SignalHeader SignalHeader
} }
func (signal CreateSignal) Header() *SignalHeader {
return &signal.SignalHeader
}
func (signal CreateSignal) Permission() Tree { func (signal CreateSignal) Permission() Tree {
return Tree{ return Tree{
SerializedType(CreateSignalType): nil, SerializedType(CreateSignalType): nil,
@ -113,9 +114,6 @@ func NewCreateSignal() *CreateSignal {
type StartSignal struct { type StartSignal struct {
SignalHeader SignalHeader
} }
func (signal StartSignal) Header() *SignalHeader {
return &signal.SignalHeader
}
func (signal StartSignal) Permission() Tree { func (signal StartSignal) Permission() Tree {
return Tree{ return Tree{
SerializedType(StartSignalType): nil, SerializedType(StartSignalType): nil,
@ -130,9 +128,6 @@ func NewStartSignal() *StartSignal {
type StopSignal struct { type StopSignal struct {
SignalHeader SignalHeader
} }
func (signal StopSignal) Header() *SignalHeader {
return &signal.SignalHeader
}
func (signal StopSignal) Permission() Tree { func (signal StopSignal) Permission() Tree {
return Tree{ return Tree{
SerializedType(StopSignalType): nil, SerializedType(StopSignalType): nil,
@ -148,9 +143,6 @@ type ErrorSignal struct {
SignalHeader SignalHeader
Error string Error string
} }
func (signal ErrorSignal) Header() *SignalHeader {
return &signal.SignalHeader
}
func (signal ErrorSignal) Permission() Tree { func (signal ErrorSignal) Permission() Tree {
return Tree{ return Tree{
SerializedType(ErrorSignalType): nil, SerializedType(ErrorSignalType): nil,
@ -166,9 +158,6 @@ func NewErrorSignal(req_id uuid.UUID, fmt_string string, args ...interface{}) Si
type ACLTimeoutSignal struct { type ACLTimeoutSignal struct {
SignalHeader SignalHeader
} }
func (signal ACLTimeoutSignal) Header() *SignalHeader {
return &signal.SignalHeader
}
func (signal ACLTimeoutSignal) Permission() Tree { func (signal ACLTimeoutSignal) Permission() Tree {
return Tree{ return Tree{
SerializedType(ACLTimeoutSignalType): nil, SerializedType(ACLTimeoutSignalType): nil,
@ -186,9 +175,6 @@ type StatusSignal struct {
Source NodeID `gv:"source"` Source NodeID `gv:"source"`
Status string `gv:"status"` Status string `gv:"status"`
} }
func (signal StatusSignal) Header() *SignalHeader {
return &signal.SignalHeader
}
func (signal StatusSignal) Permission() Tree { func (signal StatusSignal) Permission() Tree {
return Tree{ return Tree{
SerializedType(StatusSignalType): nil, SerializedType(StatusSignalType): nil,
@ -207,9 +193,6 @@ type LinkSignal struct {
NodeID NodeID
Action string Action string
} }
func (signal LinkSignal) Header() *SignalHeader {
return &signal.SignalHeader
}
const ( const (
LinkActionBase = "LINK_ACTION" LinkActionBase = "LINK_ACTION"
@ -235,9 +218,6 @@ type LockSignal struct {
SignalHeader SignalHeader
State string State string
} }
func (signal LockSignal) Header() *SignalHeader {
return &signal.SignalHeader
}
const ( const (
LockStateBase = "LOCK_STATE" LockStateBase = "LOCK_STATE"
@ -262,9 +242,6 @@ type ReadSignal struct {
SignalHeader SignalHeader
Extensions map[ExtType][]string `json:"extensions"` Extensions map[ExtType][]string `json:"extensions"`
} }
func (signal ReadSignal) Header() *SignalHeader {
return &signal.SignalHeader
}
func (signal ReadSignal) Permission() Tree { func (signal ReadSignal) Permission() Tree {
ret := Tree{} ret := Tree{}
@ -290,9 +267,6 @@ type ReadResultSignal struct {
NodeType NodeType NodeType NodeType
Extensions map[ExtType]map[string]SerializedValue Extensions map[ExtType]map[string]SerializedValue
} }
func (signal ReadResultSignal) Header() *SignalHeader {
return &signal.SignalHeader
}
func (signal ReadResultSignal) Permission() Tree { func (signal ReadResultSignal) Permission() Tree {
return Tree{ return Tree{
SerializedType(ReadResultSignalType): nil, SerializedType(ReadResultSignalType): nil,