markbates / pkger

Embed static files in Go binaries (replacement for gobuffalo/packr)
MIT License
1.18k stars 60 forks source link

Go 1.18 Type Parameters Support #153

Open buddy-sandidge opened 2 years ago

buddy-sandidge commented 2 years ago

Running pkger 1.17.1 will error when running on Go 1.18 code that uses type parameters/generics. An example can be found in this gist.

$ pkger
2022/03/30 13:10:19 /tmp/pkger-test/main.go:10:13: expected '(', found '[' (and 5 more errors): ParseDir failed /tmp/pkger-test: /tmp/pkger-test

An example of Go code that will cause the error.

package main

import (
    "io"
    "os"

    "github.com/markbates/pkger"
)

func Example[T any]() {}

func main() {
    f, err := pkger.Open("/file.txt")
    if err != nil {
        panic(err)
    }
    defer func() { _ = f.Close() }()

    if _, err := io.Copy(os.Stdout, f); err != nil {
        panic(err)
    }
}