53 lines
1.3 KiB
Go
53 lines
1.3 KiB
Go
package pipeline_api
|
|
|
|
import (
|
|
"context"
|
|
"net/http"
|
|
|
|
"git.ohea.xyz/cursorius/server/jobscheduler"
|
|
apiv1 "git.ohea.xyz/cursorius/server/proto/gen/api/v1"
|
|
"git.ohea.xyz/cursorius/server/proto/gen/api/v1/apiv1connect"
|
|
"github.com/bufbuild/connect-go"
|
|
"github.com/op/go-logging"
|
|
)
|
|
|
|
var log = logging.MustGetLogger("cursorius-server")
|
|
|
|
type ApiServer struct {
|
|
runCh chan jobscheduler.Run
|
|
}
|
|
|
|
func (s *ApiServer) GetRunner(
|
|
ctx context.Context,
|
|
req *connect.Request[apiv1.GetRunnerRequest],
|
|
) (*connect.Response[apiv1.GetRunnerResponse], error) {
|
|
|
|
res := connect.NewResponse(&apiv1.GetRunnerResponse{
|
|
RunnerId: 0,
|
|
})
|
|
res.Header().Set("GetRunner-Version", "v1")
|
|
return res, nil
|
|
}
|
|
|
|
func (s *ApiServer) RunCommand(
|
|
ctx context.Context,
|
|
req *connect.Request[apiv1.RunCommandRequest],
|
|
) (*connect.Response[apiv1.RunCommandResponse], error) {
|
|
|
|
res := connect.NewResponse(&apiv1.RunCommandResponse{
|
|
ReturnCode: 0,
|
|
Stdout: "",
|
|
Stderr: "",
|
|
})
|
|
res.Header().Set("RunCommand-Version", "v1")
|
|
return res, nil
|
|
}
|
|
|
|
func CreateHandler(mux *http.ServeMux, runCh chan jobscheduler.Run) {
|
|
api_server := &ApiServer{runCh: runCh}
|
|
path, handler := apiv1connect.NewGetRunnerServiceHandler(api_server)
|
|
mux.Handle(path, handler)
|
|
path, handler = apiv1connect.NewRunCommandServiceHandler(api_server)
|
|
mux.Handle(path, handler)
|
|
}
|