Visitar URL original
Panic when using interfaces for Dependency · Issue #1 · danielgtaylor/huma · GitHub
Skip to content

Panic when using interfaces for Dependency #1

Closed

Description

@hvanvoorhis-ISP
package main

import (
	"context"
	"net/http"

	"github.com/danielgtaylor/huma"
)

type Server interface {
	Go() bool
}

type ServerImpl struct{}

func (_ ServerImpl) Go() bool {
	return true
}

func main() {
	test()
}

func test() {

	apiMoc := &ServerImpl{}
	var server Server = apiMoc
	r := huma.NewRouter("demo", "1.0.0", huma.ProdServer("http://localhost:8888"))
	bindRoutes(server, r)

}

func bindRoutes(server Server, r *huma.Router) {

	sourceAPI := huma.SimpleDependency(server)

	captures := r.Resource("/v1/captures").With(huma.ContextDependency())

	captures.With(
		huma.ResponseError(http.StatusInternalServerError, "Server failure"),
		sourceAPI).Get("demo",
		func(ctx context.Context, server Server) bool {
			return server.Go()
		},
	)
}

Get the panic panic: return type should be *main.ServerImpl but got main.Server: dependency invalid

Activity

  1. hvanvoorhis-ISP commented on Jun 1, 2020

    @hvanvoorhis-ISP
    ContributorAuthor

    resolved

  2. added a commit that references this issue on May 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions