Skip to content
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

Cannot run included middleware HelloMiddlewareLoad #875

Open
a9z opened this issue Apr 12, 2024 · 0 comments
Open

Cannot run included middleware HelloMiddlewareLoad #875

a9z opened this issue Apr 12, 2024 · 0 comments
Labels

Comments

@a9z
Copy link

a9z commented Apr 12, 2024

Building prest from sources.

In the prest.toml file defined

pluginpath = "./lib"
[pluginmiddlewarelist]
file = "hello"
func = "Hello"

module builded with command
go build -o ./lib/middlewares/hello.so -buildmode=plugin ./lib/src/middlewares/hello.go

(please fix typo mistake in included ./lib/src/middlewares/hello.go
// BUILD:
// go build -o ./lib/midllewares/hello.so -buildmode=plugin ./lib/src/middlewares/hello.go
)

on execute prest with command

go run cmd/prestd/main.go

2024/04/12 12:04:32 it not a negroni middleware function: Hello

Adding some details by modifying ./plugins/middleware.go

 // Exec (call) function name, return `negroni.HandlerFunc`
        handlerFunc, ok := f.(func(rw http.ResponseWriter, rq *http.Request, next http.HandlerFunc))
        if !ok {
                log.Printf("it not a negroni middleware function: %s", funcName)
+                log.Printf("functionref: %s", f)
+                log.Printf("handlerFunc: %s", handlerFunc)
                return
        }

taken

2024/04/12 12:24:40 functionref: %!s(func() negroni.Handler=0x7f2051611be0)
2024/04/12 12:24:40 handlerFunc: %!s(negroni.HandlerFunc=)

cat ./lib/src/middlewares/hello.go


// nolint
// all plugins must have their package name as `main`
// each plugin is isolated at compile time
package main

import (
        "net/http"

        "github.com/urfave/negroni/v3"
)

// BUILD:
// go build -o ./lib/middlewares/hello.so -buildmode=plugin ./lib/src/middlewares/hello.go
func HelloMiddlewareLoad() negroni.Handler {
        return negroni.HandlerFunc(func(rw http.ResponseWriter, rq *http.Request, next http.HandlerFunc) {
                rw.Header().Add("X-Hello-Middleware", "Hello Middleware")
                next(rw, rq)
        })
}

go version go1.22.2 linux/amd64

@arxdsilva arxdsilva added the bug label Apr 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants