go语言框架martini

martini学习

运行 server.go 文件的前提

1.安装go运行环境:https://golang.org/doc/install

2.go get github.com/go-martini/martini

 

文件名 server.go

 

package main

import (
"github.com/go-martini/martini"
"fmt"
)

func main() {
m := martini.Classic()
m.Get("/api", func() string {
return "Hello world!"
})

//m.Get("/hello/:name", func(params martini.Params) string {
// return "Hello " + params["name"]
//})

//m.Get("/hello/(?P<name>[a-zA-Z]+)", func(params martini.Params) string {
// return fmt.Sprintf ("Hello %s", params["name"])
//})
m.Group("/books", func(r martini.Router) {
r.Get("/:id/:name", GetBooks)
//r.Post("/new", NewBook)
//r.Put("/update/:id", UpdateBook)
//r.Delete("/delete/:id", DeleteBook)
})
m.Run()
}


func GetBooks(params martini.Params) string{
fmt.Println(params)
return "true"
}

posted on 2021-07-02 10:41  sosogengdongni  阅读(160)  评论(0编辑  收藏  举报

导航