/
lua.go
51 lines (42 loc) · 1.1 KB
/
lua.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package envoyconfig
import (
"embed"
"io/fs"
)
//go:embed luascripts
var luaFS embed.FS
var luascripts struct {
ExtAuthzSetCookie string
CleanUpstream string
RemoveImpersonateHeaders string
RewriteHeaders string
SetClientCertificateMetadata string
}
func init() {
fileToField := map[string]*string{
"luascripts/clean-upstream.lua": &luascripts.CleanUpstream,
"luascripts/ext-authz-set-cookie.lua": &luascripts.ExtAuthzSetCookie,
"luascripts/remove-impersonate-headers.lua": &luascripts.RemoveImpersonateHeaders,
"luascripts/rewrite-headers.lua": &luascripts.RewriteHeaders,
"luascripts/set-client-certificate-metadata.lua": &luascripts.SetClientCertificateMetadata,
}
err := fs.WalkDir(luaFS, "luascripts", func(p string, d fs.DirEntry, err error) error {
if err != nil {
return err
}
if d.IsDir() {
return nil
}
bs, err := luaFS.ReadFile(p)
if err != nil {
return err
}
if ptr, ok := fileToField[p]; ok {
*ptr = string(bs)
}
return nil
})
if err != nil {
panic(err)
}
}