draincloud-core/internal/resolvers/plugin_name/plugin_name.go

34 lines
794 B
Go
Raw Normal View History

2025-01-10 23:09:37 +00:00
package pluginname
import (
"context"
"git.optclblast.xyz/draincloud/draincloud-core/internal/common"
"github.com/gin-gonic/gin"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
)
const (
PluginNameResolverName = "plugin_name"
)
type PluginNameResolver struct{}
func (p *PluginNameResolver) Resolve(ctx context.Context, req *common.Request, rawReq any) error {
ginCtx, ok := rawReq.(*gin.Context)
if !ok {
return status.Errorf(codes.Internal, "invalid request type")
}
pluginName := ginCtx.Param("plugin_name")
if pluginName == "" {
return status.Error(codes.InvalidArgument, "plugin name is empty")
}
req.ResolveValues.Store(PluginNameResolverName, pluginName)
return nil
}
func (p *PluginNameResolver) GetRequiredResolveParams() []string {
return nil
}