diff --git a/cchat.go b/cchat.go index 103c23a..5a28dd5 100644 --- a/cchat.go +++ b/cchat.go @@ -318,12 +318,10 @@ type Completer interface { } // Configurator is an interface which the backend can implement for a primitive -// configuration API. Since these methods do return an error, they are allowed -// to do IO. The frontend should handle this appropriately, including running -// them asynchronously. +// configuration API. type Configurator interface { - SetConfiguration(context.Context, map[string]string) error // Blocking - Configuration(context.Context) (map[string]string, error) // Blocking + SetConfiguration(map[string]string) error + Configuration() map[string]string } // Editor adds message editing to the messenger. Only EditMessage can do IO. diff --git a/cmd/internal/cchat-generator/generate_interface.go b/cmd/internal/cchat-generator/generate_interface.go index f47e4f4..e0ebf00 100644 --- a/cmd/internal/cchat-generator/generate_interface.go +++ b/cmd/internal/cchat-generator/generate_interface.go @@ -66,6 +66,7 @@ func generateInterfaces(ifaces []repository.Interface) jen.Code { stmt.Params(generateFuncParams(method.Returns, method.ErrorType)...) case repository.SetterMethod: stmt.Params(generateFuncParams(method.Parameters, "")...) + stmt.Params(generateFuncParamsErr(repository.NamedType{}, method.ErrorType)...) case repository.IOMethod: stmt.Params(generateFuncParamsCtx(method.Parameters, "")...) stmt.Params(generateFuncParamsErr(method.ReturnValue, method.ErrorType)...) diff --git a/repository/gob/repository.gob b/repository/gob/repository.gob index 2257f30..b608ccb 100644 Binary files a/repository/gob/repository.gob and b/repository/gob/repository.gob differ diff --git a/repository/interface.go b/repository/interface.go index a3345e0..97e350b 100644 --- a/repository/interface.go +++ b/repository/interface.go @@ -78,6 +78,10 @@ type SetterMethod struct { // Parameters is the list of parameters in the function. These parameters // should be the parameters to set. Parameters []NamedType + // ErrorType is non-empty if the function returns an error at the end of + // returns. An error may be returned from the backend if the input is + // invalid, but it must not do IO. Frontend setters must never error. + ErrorType string } // IOMethod is a regular method that can do IO and thus is blocking. These diff --git a/repository/main.go b/repository/main.go index 17525d2..347c3fd 100644 --- a/repository/main.go +++ b/repository/main.go @@ -817,18 +817,15 @@ var Main = Packages{ }, { Comment: Comment{` Configurator is an interface which the backend can implement for a - primitive configuration API. Since these methods do return an error, - they are allowed to do IO. The frontend should handle this - appropriately, including running them asynchronously. + primitive configuration API. `}, Name: "Configurator", Methods: []Method{ - IOMethod{ - method: method{Name: "Configuration"}, - ReturnValue: NamedType{Type: "map[string]string"}, - ErrorType: "error", + GetterMethod{ + method: method{Name: "Configuration"}, + Returns: []NamedType{{Type: "map[string]string"}}, }, - IOMethod{ + SetterMethod{ method: method{Name: "SetConfiguration"}, Parameters: []NamedType{{Type: "map[string]string"}}, ErrorType: "error",