GolangNote

Golang笔记

golang goji 同时实现接口和静态文件服务

Permalink

golang goji 同时实现接口和静态文件服务

golang goji 同时实现接口和静态文件服务

Go: main
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
package main

import (
	"fmt"
	"net/http"

	"github.com/zenazn/goji"
	"github.com/zenazn/goji/web"
)

func apiExampleHandler(context web.C, resp http.ResponseWriter, req *http.Request) {
	fmt.Fprint(resp, "You've hit the API!")
}

func main() {
	goji.Handle("/api", apiExampleHandler)

	// Static file handler should generally be the last handler registered. Otherwise, it'll match every path.
	// Be sure to use an absolute path.
	staticFilesLocation := "/Users/Retired/Go/src/github.com/Retired/26320144/public"
	goji.Handle("/*", http.FileServer(http.Dir(staticFilesLocation)))

	goji.Serve()
}

Related articles

goji + SSDB 构建的应用

已经过了学生的年纪,学习新东西不那么快,尝试从python 转向golang,就从博客程序开始。...

Write a Comment to "golang goji 同时实现接口和静态文件服务"

Submit Comment Login
Based on Golang + fastHTTP + sdb | go1.16.5 Processed in 0ms