mirror of
https://github.com/zrepl/zrepl.git
synced 2024-11-25 09:54:47 +01:00
move wakeup to client package and extract http client
This commit is contained in:
parent
7dd49b835a
commit
e495824834
@ -1,38 +1,15 @@
|
||||
package main
|
||||
package client
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"encoding/json"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/zrepl/zrepl/config"
|
||||
"github.com/zrepl/zrepl/daemon"
|
||||
"io"
|
||||
"net"
|
||||
"net/http"
|
||||
"net"
|
||||
"context"
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"io"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
func RunWakeup(config config.Config, args []string) error {
|
||||
if len(args) != 1 {
|
||||
return errors.Errorf("Expected 1 argument: job")
|
||||
}
|
||||
|
||||
httpc, err := controlHttpClient(config.Global.Control.SockPath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = jsonRequestResponse(httpc, daemon.ControlJobEndpointWakeup,
|
||||
struct {
|
||||
Name string
|
||||
}{
|
||||
Name: args[0],
|
||||
},
|
||||
struct{}{},
|
||||
)
|
||||
return err
|
||||
}
|
||||
|
||||
func controlHttpClient(sockpath string) (client http.Client, err error) {
|
||||
return http.Client{
|
||||
Transport: &http.Transport{
|
||||
@ -66,3 +43,4 @@ func jsonRequestResponse(c http.Client, endpoint string, req interface{}, res in
|
||||
|
||||
return nil
|
||||
}
|
||||
|
28
client/wakeup.go
Normal file
28
client/wakeup.go
Normal file
@ -0,0 +1,28 @@
|
||||
package client
|
||||
|
||||
import (
|
||||
"github.com/pkg/errors"
|
||||
"github.com/zrepl/zrepl/config"
|
||||
"github.com/zrepl/zrepl/daemon"
|
||||
)
|
||||
|
||||
func RunWakeup(config config.Config, args []string) error {
|
||||
if len(args) != 1 {
|
||||
return errors.Errorf("Expected 1 argument: job")
|
||||
}
|
||||
|
||||
httpc, err := controlHttpClient(config.Global.Control.SockPath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = jsonRequestResponse(httpc, daemon.ControlJobEndpointWakeup,
|
||||
struct {
|
||||
Name string
|
||||
}{
|
||||
Name: args[0],
|
||||
},
|
||||
struct{}{},
|
||||
)
|
||||
return err
|
||||
}
|
Loading…
Reference in New Issue
Block a user