Configurator to be SetterMethods

This commit changes Configurator's methods to be SetterMethods instead
of IOMethods, as Configurator is specifically made for frontend-managed
settings just for the backend, so no storing/loading is needed on the
backend's side.

This commit also changes SetterMethod to allow methods done to the
backend to error out, in case the setting value is invalid somehow.
Setter methods that are called by the backend (as opposed to the
frontend) must never error.
This commit is contained in:
diamondburned 2021-05-01 17:22:01 -07:00
parent 86956a65ec
commit 4e11444f6c
5 changed files with 13 additions and 13 deletions

View File

@ -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.

View File

@ -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)...)

Binary file not shown.

View File

@ -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

View File

@ -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",