initial commit
This commit is contained in:
52
do.go
Normal file
52
do.go
Normal file
@ -0,0 +1,52 @@
|
||||
package niri
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
func (c *Client) Action(action Action) error {
|
||||
// print request and response to console:
|
||||
//
|
||||
// io.Copy(os.Stdout, asJsonReader(action))
|
||||
// r, err := readSocketRaw(c.GetSocketPath(), asJsonReader(action))
|
||||
// if err != nil {
|
||||
// return err
|
||||
// }
|
||||
// io.Copy(os.Stdout, r)
|
||||
// return nil
|
||||
|
||||
resp := readSocket[string](c.GetSocketPath(), asJsonReader(action))
|
||||
if resp.Err != nil {
|
||||
return errors.New(*resp.Err)
|
||||
} else if resp.OK == nil {
|
||||
return errors.New("unexpected response value: nil")
|
||||
} else if *resp.OK != "Handled" {
|
||||
return fmt.Errorf("unexpected response value: %s", *resp.OK)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *Client) Output(outputAction OutputActionRequest) error {
|
||||
body := map[string]OutputActionRequest{"Output": outputAction}
|
||||
|
||||
// print request and response to console:
|
||||
//
|
||||
// io.Copy(os.Stdout, asJsonReader(body))
|
||||
// r, err := readSocketRaw(c.GetSocketPath(), asJsonReader(body))
|
||||
// if err != nil {
|
||||
// return err
|
||||
// }
|
||||
// io.Copy(os.Stdout, r)
|
||||
// return nil
|
||||
|
||||
resp := readSocket[outputActionResponse](c.GetSocketPath(), asJsonReader(body))
|
||||
if resp.Err != nil {
|
||||
return errors.New(*resp.Err)
|
||||
} else if resp.OK == nil {
|
||||
return errors.New("unexpected response value: nil")
|
||||
} else if resp.OK.OutputConfigChanged != "Applied" {
|
||||
return fmt.Errorf("unexpected response value: %s", resp.OK.OutputConfigChanged)
|
||||
}
|
||||
return nil
|
||||
}
|
Reference in New Issue
Block a user