12
10

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Gowebで静的ページとRESTful APIを両方ともハンドリングする

Last updated at Posted at 2013-03-01

http://localhost:8080/」でアクセスされたら、index.htmlを「http://localhost:8080/api/リソース名」でアクセスされたらRestful APIでハンドリングするには以下の様にハンドリングすればいい。

main.go
package main

import (
	"fmt"
	"github.com/stretchrcom/goweb/goweb"
	"net/http"
)

func main() {

	// Gowebのコントローラーの登録とかをする

	// RESTful APIのハンドリング -> Gowebへ
	http.Handle("/api/", http.StripPrefix("/api", goweb.DefaultHttpHandler))

	// 静的ファイルのハンドリング -> ファイルサーバへ
	http.Handle("/", http.FileServer(http.Dir("static")))

	// Webサーバの開始
	http.Handle("/", http.FileServer(http.Dir("static")))
}

12
10
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
12
10

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?