Support syscall
This commit is contained in:
parent
05de0670ea
commit
d1ab6ed489
12 changed files with 247 additions and 8 deletions
3
pkg/plugins/fixtures/src/testpluginsafe/go.mod
Normal file
3
pkg/plugins/fixtures/src/testpluginsafe/go.mod
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
module testpluginsafe
|
||||
|
||||
go 1.23.0
|
||||
21
pkg/plugins/fixtures/src/testpluginsafe/testpluginsafe.go
Normal file
21
pkg/plugins/fixtures/src/testpluginsafe/testpluginsafe.go
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
package testpluginsafe
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
Message string
|
||||
}
|
||||
|
||||
func CreateConfig() *Config {
|
||||
return &Config{Message: "safe plugin"}
|
||||
}
|
||||
|
||||
func New(ctx context.Context, next http.Handler, config *Config, name string) (http.Handler, error) {
|
||||
return http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) {
|
||||
rw.Header().Set("X-Test-Plugin", "safe")
|
||||
next.ServeHTTP(rw, req)
|
||||
}), nil
|
||||
}
|
||||
3
pkg/plugins/fixtures/src/testpluginsyscall/go.mod
Normal file
3
pkg/plugins/fixtures/src/testpluginsyscall/go.mod
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
module testpluginsyscall
|
||||
|
||||
go 1.23.0
|
||||
|
|
@ -0,0 +1,29 @@
|
|||
package testpluginsyscall
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"syscall"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
Message string
|
||||
}
|
||||
|
||||
func CreateConfig() *Config {
|
||||
return &Config{Message: "syscall plugin"}
|
||||
}
|
||||
|
||||
func New(ctx context.Context, next http.Handler, config *Config, name string) (http.Handler, error) {
|
||||
// Use syscall and unsafe to test they're available
|
||||
pid := syscall.Getpid()
|
||||
size := unsafe.Sizeof(int(0))
|
||||
|
||||
return http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) {
|
||||
rw.Header().Set("X-Test-Plugin", "syscall")
|
||||
rw.Header().Set("X-Test-PID", string(rune(pid)))
|
||||
rw.Header().Set("X-Test-Size", string(rune(size)))
|
||||
next.ServeHTTP(rw, req)
|
||||
}), nil
|
||||
}
|
||||
3
pkg/plugins/fixtures/src/testpluginunsafe/go.mod
Normal file
3
pkg/plugins/fixtures/src/testpluginunsafe/go.mod
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
module testpluginunsafe
|
||||
|
||||
go 1.23.0
|
||||
|
|
@ -0,0 +1,26 @@
|
|||
package testpluginunsafe
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net/http"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
type Config struct {
|
||||
Message string
|
||||
}
|
||||
|
||||
func CreateConfig() *Config {
|
||||
return &Config{Message: "unsafe only plugin"}
|
||||
}
|
||||
|
||||
func New(ctx context.Context, next http.Handler, config *Config, name string) (http.Handler, error) {
|
||||
// Use ONLY unsafe to test it's available
|
||||
size := unsafe.Sizeof(int(0))
|
||||
|
||||
return http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) {
|
||||
rw.Header().Set("X-Test-Plugin", "unsafe-only")
|
||||
rw.Header().Set("X-Test-Unsafe-Size", string(rune(size)))
|
||||
next.ServeHTTP(rw, req)
|
||||
}), nil
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue