Skip to content

Commit

Permalink
Pass param value
Browse files Browse the repository at this point in the history
  • Loading branch information
akclace committed Oct 10, 2024
1 parent 448e86b commit 8303225
Showing 1 changed file with 24 additions and 4 deletions.
28 changes: 24 additions & 4 deletions internal/app/action/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,16 @@ package action

import (
"embed"
"fmt"
"html/template"
"io/fs"
"net/http"
"path"
"slices"
"strconv"

"github.com/claceio/clace/internal/app/apptype"
"github.com/claceio/clace/internal/app/starlark_type"
"github.com/go-chi/chi"
"go.starlark.net/starlark"
)
Expand Down Expand Up @@ -82,17 +85,34 @@ func (a *Action) runHandler(w http.ResponseWriter, r *http.Request) {
type ParamDef struct {
Name string
Description string
Value string
Value any
}

func (a *Action) getForm(w http.ResponseWriter, r *http.Request) {
params := make([]ParamDef, 0, len(a.params))
for _, p := range a.params {
params = append(params, ParamDef{
param := ParamDef{
Name: p.Name,
Description: p.Description,
Value: a.paramValues[p.Name],
})
}

value, ok := a.paramValues[p.Name]
if !ok {
http.Error(w, fmt.Sprintf("missing param value for %s", p.Name), http.StatusInternalServerError)
return
}

param.Value = value // Default to string format
if p.Type == starlark_type.BOOLEAN {
boolValue, err := strconv.ParseBool(value)
if err != nil {
http.Error(w, fmt.Sprintf("invalid value for %s: %s", p.Name, value), http.StatusInternalServerError)
return
}
param.Value = boolValue
}

params = append(params, param)
}

input := map[string]any{
Expand Down

0 comments on commit 8303225

Please sign in to comment.