Merge branch 'proxima-centauri' into test-pc

This commit is contained in:
schulze 2023-04-25 15:05:44 +02:00
commit ea12cd4fe6
4 changed files with 14 additions and 13 deletions

View File

@ -14,7 +14,7 @@ func main() {
uuid := uuid.MustParse("87e79cbc-6df6-4462-8412-85d6c473e3b1") uuid := uuid.MustParse("87e79cbc-6df6-4462-8412-85d6c473e3b1")
m := pcsdk.NewCommandCreate(5555, 8080, ip, state.CustomUUID(uuid)) m := pcsdk.NewCommandCreate(5555, 8080, ip, state.CustomUUID(uuid))
err := m.Execute("http://localhost:3000") err := m.Execute(netip.MustParseAddrPort("127.0.0.1:3000"))
if err != nil { if err != nil {
fmt.Printf("error executing create command: %s\n", err) fmt.Printf("error executing create command: %s\n", err)
} else { } else {

View File

@ -2,6 +2,7 @@ package main
import ( import (
"fmt" "fmt"
"net/netip"
"github.com/google/uuid" "github.com/google/uuid"
"github.com/thefeli73/polemos/pcsdk" "github.com/thefeli73/polemos/pcsdk"
@ -12,10 +13,10 @@ func main() {
uuid := uuid.MustParse("87e79cbc-6df6-4462-8412-85d6c473e3b1") uuid := uuid.MustParse("87e79cbc-6df6-4462-8412-85d6c473e3b1")
m := pcsdk.NewCommandDelete(state.CustomUUID(uuid)) m := pcsdk.NewCommandDelete(state.CustomUUID(uuid))
err := m.Execute("http://localhost:3000") err := m.Execute(netip.MustParseAddrPort("127.0.0.1:3000"))
if err != nil { if err != nil {
fmt.Printf("error executing modify command: %s\n", err) fmt.Printf("error executing delete command: %s\n", err)
} else { } else {
fmt.Println("executing modify command completed") fmt.Println("executing delete command completed")
} }
} }

View File

@ -14,7 +14,7 @@ func main() {
uuid := uuid.MustParse("87e79cbc-6df6-4462-8412-85d6c473e3b1") uuid := uuid.MustParse("87e79cbc-6df6-4462-8412-85d6c473e3b1")
m := pcsdk.NewCommandModify(9111, ip, state.CustomUUID(uuid)) m := pcsdk.NewCommandModify(9111, ip, state.CustomUUID(uuid))
err := m.Execute("http://localhost:3000") err := m.Execute(netip.MustParseAddrPort("127.0.0.1:3000"))
if err != nil { if err != nil {
fmt.Printf("error executing modify command: %s\n", err) fmt.Printf("error executing modify command: %s\n", err)
} else { } else {

View File

@ -14,7 +14,7 @@ import (
) )
type ExecuteCommand interface { type ExecuteCommand interface {
Execute(string) error Execute(netip.AddrPort) error
} }
type response struct { type response struct {
@ -33,14 +33,14 @@ type CommandCreate struct {
Id string `json:"id"` Id string `json:"id"`
} }
func (c ProxyCommandCreate) Execute(url string) error { func (c ProxyCommandCreate) Execute(url netip.AddrPort) error {
data, err := json.Marshal(c) data, err := json.Marshal(c)
if err != nil { if err != nil {
return errors.New(fmt.Sprintf("could not serialize: %s\n", err)) return errors.New(fmt.Sprintf("could not serialize: %s\n", err))
} }
requestURL := fmt.Sprintf("%s/command", url) requestURL := fmt.Sprintf("http://%s:%d/command", url.Addr().String(), url.Port())
fmt.Println(requestURL)
bodyReader := bytes.NewReader(data) bodyReader := bytes.NewReader(data)
res, err := http.DefaultClient.Post(requestURL, "application/json", bodyReader) res, err := http.DefaultClient.Post(requestURL, "application/json", bodyReader)
@ -78,13 +78,13 @@ type CommandModify struct {
Id string `json:"id"` Id string `json:"id"`
} }
func (c ProxyCommandModify) Execute(url string) error { func (c ProxyCommandModify) Execute(url netip.AddrPort) error {
data, err := json.Marshal(c) data, err := json.Marshal(c)
if err != nil { if err != nil {
return errors.New(fmt.Sprintf("could not serialize: %s\n", err)) return errors.New(fmt.Sprintf("could not serialize: %s\n", err))
} }
requestURL := fmt.Sprintf("%s/command", url) requestURL := fmt.Sprintf("http://%s:%d/command", url.Addr().String(), url.Port())
bodyReader := bytes.NewReader(data) bodyReader := bytes.NewReader(data)
@ -121,13 +121,13 @@ type CommandDelete struct {
Id string `json:"id"` Id string `json:"id"`
} }
func (c ProxyCommandDelete) Execute(url string) error { func (c ProxyCommandDelete) Execute(url netip.AddrPort) error {
data, err := json.Marshal(c) data, err := json.Marshal(c)
if err != nil { if err != nil {
return errors.New(fmt.Sprintf("could not serialize: %s\n", err)) return errors.New(fmt.Sprintf("could not serialize: %s\n", err))
} }
requestURL := fmt.Sprintf("%s/command", url) requestURL := fmt.Sprintf("http://%s:%d/command", url.Addr().String(), url.Port())
bodyReader := bytes.NewReader(data) bodyReader := bytes.NewReader(data)