Skip to content

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

@tablecell

Description

@tablecell

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions