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

invalid operation: "CatchAll:" + c.Get("**") (mismatched types string and interface {}) #1

Open
tablecell opened this issue Aug 20, 2021 · 0 comments

Comments

@tablecell
Copy link

example/main.go

 package main

import (
	"io"
	"net/http"

	"github.com/typepress/rivet"
)

func empty() { println("empty") }

func helloWorld(w http.ResponseWriter, req *http.Request) {
	w.Write([]byte("Hello World"))
}

func hello(params rivet.Params, w http.ResponseWriter) {
	io.WriteString(w, "Hello ")
	w.Write([]byte(params.Get("name")))
}

func catchAll(c rivet.Context) {
	c.WriteString("CatchAll:" + c.Get("**"))
}

func letGo(c *rivet.Context) {
	c.Map("Death is coming. Let's Go!")
}

func goGo(c *rivet.Context) {
	var s string

	i, has := c.Pick(rivet.TypePointerOf("string"))
	if has {
		s, _ = i.(string)
	}

	c.WriteString(c.Get("name") + "! " + s)
}

func main() {

	mux := rivet.New()

	mux.Get("/", helloWorld)
	mux.Get("/empty", empty)
	mux.Get("/hi/:name/path/to", hello)
	mux.Get("/hi/:name/path", hello)
	mux.Get("/:name", letGo, goGo)
	mux.Get("/hi/**", catchAll)

	// rivet.Router 符合 http.Handler 接口
	http.ListenAndServe(":3282", mux)
}

.\main.go:22:28: invalid operation: "CatchAll:" + c.Get("") (mismatched types string and interface {})
.\main.go:22:36: cannot use "
" (type untyped string) as type uint in argument to c.Get
.\main.go:26:3: c.Map undefined (type *rivet.Context is pointer to interface, not interface)
.\main.go:32:13: c.Pick undefined (type *rivet.Context is pointer to interface, not interface)
.\main.go:32:19: undefined: rivet.TypePointerOf
.\main.go:37:3: c.WriteString undefined (type *rivet.Context is pointer to interface, not interface)
.\main.go:37:17: c.Get undefined (type *rivet.Context is pointer to interface, not interface)
.\main.go:42:9: undefined: rivet.New

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant