M go.mod => go.mod +1 -1
@@ 3,7 3,7 @@ module git.src.quest/~liljamo/emerwen-web
go 1.23.3
require (
- git.src.quest/~liljamo/emerwen-proto v0.0.0-20241120090258-63eb26154b46
+ git.src.quest/~liljamo/emerwen-proto v0.0.0-20241126103339-8aa1fdcc154e
github.com/a-h/templ v0.2.793
github.com/alexedwards/scs/v2 v2.8.0
github.com/coreos/go-oidc/v3 v3.11.0
M go.sum => go.sum +2 -2
@@ 1,5 1,5 @@
-git.src.quest/~liljamo/emerwen-proto v0.0.0-20241120090258-63eb26154b46 h1:+kCaPHVSpiXPVB5GzVP68LrgJ9HvYE7p7tnNUHjpGfM=
-git.src.quest/~liljamo/emerwen-proto v0.0.0-20241120090258-63eb26154b46/go.mod h1:TZkTqP3/rDTcJDTDU61QvV+4+TsZIvW0lt4hOiYCrr0=
+git.src.quest/~liljamo/emerwen-proto v0.0.0-20241126103339-8aa1fdcc154e h1:oGGhuNBEf9opVrez1lPYS64l5Nd3YEkRSfhuxCoZZFM=
+git.src.quest/~liljamo/emerwen-proto v0.0.0-20241126103339-8aa1fdcc154e/go.mod h1:TZkTqP3/rDTcJDTDU61QvV+4+TsZIvW0lt4hOiYCrr0=
github.com/a-h/templ v0.2.793 h1:Io+/ocnfGWYO4VHdR0zBbf39PQlnzVCVVD+wEEs6/qY=
github.com/a-h/templ v0.2.793/go.mod h1:lq48JXoUvuQrU0VThrK31yFwdRjTCnIE5bcPCM9IP1w=
github.com/alexedwards/scs/v2 v2.8.0 h1:h31yUYoycPuL0zt14c0gd+oqxfRwIj6SOjHdKRZxhEw=
M internal/client/client.go => internal/client/client.go +3 -3
@@ 20,9 20,9 @@ import (
"google.golang.org/grpc/metadata"
)
-// Client wraps the emerwen gRPC WebToMasterClient, along with a Context.
+// Client wraps the emerwen gRPC CoordinatorControlServiceClient, along with a Context.
type Client struct {
- Client proto.WebToMasterClient
+ Client proto.CoordinatorControlServiceClient
Ctx context.Context
}
@@ 33,7 33,7 @@ func NewClient(c *config.Config) *Client {
slog.Error("yay")
}
- client := proto.NewWebToMasterClient(conn)
+ client := proto.NewCoordinatorControlServiceClient(conn)
// TODO: config read auth_token from file
ctx := metadata.AppendToOutgoingContext(context.Background(), "authorization", "Bearer avain_perkele")
M internal/components/partials.templ => internal/components/partials.templ +17 -24
@@ 5,14 5,7 @@ import "fmt"
import "strings"
func getMethodString(target *shared.Target) string {
- switch target.Method.(type) {
- case *shared.Target_Ping:
- return "ping"
- case *shared.Target_Get:
- return "get"
- default:
- return "invalid"
- }
+ return shared.Method_name[int32(target.Method)]
}
templ PartialWorkers(workers []*shared.Worker) {
@@ 21,24 14,24 @@ templ PartialWorkers(workers []*shared.Worker) {
<div class="flex flex-col bg-slate-100 p-2">
<div class="flex items-center gap-1">
<form class="flex items-center w-full" hx-confirm="update worker name?" hx-patch="/api/worker">
- <input hidden name="id" value={ worker.Id }/>
+ <input hidden name="id" value={ worker.WorkerId }/>
<input class="border w-full" type="text" placeholder="..." name="name" value={ worker.Name }/>
<input type="submit" hidden/>
</form>
- @trash("/api/worker", worker.Id, "delete worker?")
+ @trash("/api/worker", worker.WorkerId, "delete worker?")
</div>
- @smallDetails("id", worker.Id)
+ @smallDetails("id", worker.WorkerId)
<div class="flex items-center gap-1">
<div class="min-w-max">auth token: </div>
<input class="border w-full" disabled type="password" value={ worker.AuthToken }
- id={ fmt.Sprintf("auth_key_%s", worker.Id) }
+ id={ fmt.Sprintf("auth_key_%s", worker.WorkerId) }
/>
- @eyeToggle(fmt.Sprintf("auth_key_%s", worker.Id))
+ @eyeToggle(fmt.Sprintf("auth_key_%s", worker.WorkerId))
</div>
<details>
<summary class="select-none">targets</summary>
<div class="flex flex-col gap-1 p-2">
- @newTarget(worker.Id)
+ @newTarget(worker.WorkerId)
for _, target := range worker.Targets {
@editTarget(target)
}
@@ 53,7 46,7 @@ script selectNewTargetMethod(worker_id string) {
var value = document.getElementById(worker_id + "_new_target_method_select").value;
var get_options = document.getElementById(worker_id + "_new_target_get_options");
- if (value === "get") {
+ if (value === "GET") {
get_options.style.display = "block";
} else {
get_options.style.display = "none";
@@ 75,8 68,8 @@ templ newTarget(worker_id string) {
<div>
<label>method</label>
<select onchange={ selectNewTargetMethod(worker_id) } id={ worker_id + "_new_target_method_select" } name="method">
- <option value="ping">ping</option>
- <option value="get">get</option>
+ <option value="PING">ping</option>
+ <option value="GET">get</option>
</select>
</div>
<div id={ worker_id + "_new_target_get_options"} style="display: none;">
@@ 93,9 86,9 @@ templ editTarget(target *shared.Target) {
<form class="flex flex-col bg-slate-200 p-2" hx-confirm="update target?" hx-patch="/api/target">
<div class="flex items-center gap-1">
<input class="border w-full" type="text" placeholder="..." name="name" value={ target.Name }/>
- @trash("/api/target", target.Id, "delete target?")
+ @trash("/api/target", target.TargetId, "delete target?")
</div>
- @smallDetails("id", target.Id)
+ @smallDetails("id", target.TargetId)
<div class="flex items-center gap-1">
<label>addr:</label>
<input class="border w-full" type="text" placeholder="..." name="addr" value={ target.Addr }/>
@@ 104,21 97,21 @@ templ editTarget(target *shared.Target) {
<label class="min-w-max">interval (ms):</label>
<input class="border w-full" type="number" placeholder="..." name="interval" value={ fmt.Sprint(target.Interval) }/>
</div>
- switch m := target.Method.(type) {
- case *shared.Target_Ping:
+ switch target.Method {
+ case shared.Method_PING:
<div>method: ping</div>
- case *shared.Target_Get:
+ case shared.Method_GET:
<div>method: get</div>
<div class="flex items-center gap-1">
<label class="min-w-max">ok codes:</label>
<input class="border w-full" type="text" placeholder="..." name="ok_codes"
- value={ strings.Trim(fmt.Sprint(m.Get.OkCodes), "[]") }/>
+ value={ strings.Trim(fmt.Sprint(target.OkCodes), "[]") }/>
</div>
default:
<div>invalid</div>
}
<div class="flex flex-row-reverse">
- <input hidden name="id" value={ target.Id }/>
+ <input hidden name="id" value={ target.TargetId }/>
@buttonSubmit()
</div>
</form>
M internal/handlers/api.go => internal/handlers/api.go +6 -5
@@ 85,9 85,9 @@ func APIPostTarget(client *client.Client) gin.HandlerFunc {
}
switch c.PostForm("method") {
- case "ping":
- request.Method = &proto.NewTargetRequest_Ping{}
- case "get":
+ case shared.Method_PING.String():
+ request.Method = shared.Method_PING
+ case shared.Method_GET.String():
var okCodes []int32
if okCodesStr := c.PostForm("ok_codes"); okCodesStr != "" {
@@ 105,7 105,8 @@ func APIPostTarget(client *client.Client) gin.HandlerFunc {
}
}
}
- request.Method = &proto.NewTargetRequest_Get{Get: &shared.MethodGET{OkCodes: okCodes}}
+ request.Method = shared.Method_GET
+ request.OkCodes = okCodes
default:
c.String(http.StatusBadRequest, "Bad method.")
return
@@ 160,7 161,7 @@ func APIPatchTarget(client *client.Client) gin.HandlerFunc {
return
}
}
- request.Method = &proto.PatchTargetRequest_Get{Get: &shared.MethodGET{OkCodes: okCodes}}
+ request.OkCodes = okCodes
}
response, err := client.Client.PatchTarget(client.Ctx, &request)