-
-
Notifications
You must be signed in to change notification settings - Fork 273
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Problems with gin template rendering #912
Comments
/main.go
/templates/index.html
struct{} writing methods can be rendered successfully. Error with []struct{} type in gin template rendering. |
This is likely fixed in master:
|
What version of Garble and Go are you using?
go.mod:
Go->cmd: GET: I seem to have found some clues (not sure).
OR
The reason for the error is that |
Can you share a full example to reproduce this? |
The complete file example is at the beginning of the post, with only two files ( |
This example(main.go) has the same error prompt as the example above. |
I am having a similar problem, although my use case is different. I can replicate my issue with this code, which replicates what I'm doing in my application: package main
import (
"embed"
"fmt"
"os"
"strings"
"text/template"
)
//go:embed templates
var templateFS embed.FS
type TemplateData struct {
Name string
Value string
Port int
}
func RenderTemplate[T any](src string, dest string, data T) error {
content, err := templateFS.ReadFile(src)
if err != nil {
return fmt.Errorf("failed to read template: %w", err)
}
tmpl, err := template.New(src).Parse(string(content))
if err != nil {
return fmt.Errorf("failed to parse template: %w", err)
}
var buf strings.Builder
if err := tmpl.Execute(&buf, data); err != nil {
return fmt.Errorf("failed to execute template: %w", err)
}
return os.WriteFile(dest, []byte(buf.String()), 0644)
}
func main() {
data := TemplateData{
Name: "test",
Value: "example",
Port: 8080,
}
if err := RenderTemplate("templates/config.yaml.tmpl", "config.yaml", data); err != nil {
fmt.Printf("Error rendering template: %v\n", err)
os.Exit(1)
}
} In the same directory, create another directory called
Directory structure should then match:
Running this with
Running it with
|
What version of Garble and Go are you using?
What did you do?
[]Item list,iii cannot be printed.
garble build -mod=vendor -o bin/go_go.exe main.go
/main.go
/templates/index.html
GET:
http://127.0.0.1:8080/index
Error #01: template: index.html:9:27: executing "index.html" at <$value.Size>: can't evaluate field Size in type main.B0aMZmq6
The text was updated successfully, but these errors were encountered: