コード例 #1
0
ファイル: static.go プロジェクト: jmjoy/http-api-tester
func (this *StaticController) Get() error {
	uS := this.R.URL.String()[1:] // remove fst "/"
	ext := path.Ext(uS)

	var buf []byte
	var cType string

	if mimeType, has := extMimeMap[ext]; has {
		cType = mimeType
		content := text.ProvideString(uS)
		if content == "" {
			return app.ErrNotFound
		}
		buf = []byte(content)

	} else { // is not textual file
		buf = text.ProvideBytes(uS)
		if buf == nil {
			return app.ErrNotFound
		}
	}

	this.W.Header().Set("Content-Type", cType)
	this.W.Write(buf)
	return nil
}
コード例 #2
0
ファイル: index.go プロジェクト: 292388900/http-api-tester
func (this *IndexController) indexPage() (err error) {
	_, err = io.WriteString(this.W, text.ProvideString("view/index.html"))
	return
}