This commit is contained in:
parent
029325df54
commit
a3d3155e9b
@ -4,15 +4,15 @@ import (
|
|||||||
"bytes"
|
"bytes"
|
||||||
"database/sql"
|
"database/sql"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
|
||||||
"errors"
|
"errors"
|
||||||
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"net/url"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type Application struct {
|
type Application struct {
|
||||||
@ -39,32 +39,29 @@ func (this *Application) ServeHTTP(w http.ResponseWriter, req *http.Request) {
|
|||||||
//启动实例
|
//启动实例
|
||||||
func (this *Application) Run(router Router) {
|
func (this *Application) Run(router Router) {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
this.Router = router
|
this.Router = router
|
||||||
//重新设置MethodRouter//直达路由
|
//重新设置MethodRouter//直达路由
|
||||||
this.MethodRouter=MethodRouter{}
|
this.MethodRouter = MethodRouter{}
|
||||||
modeRouterStrict:=true
|
modeRouterStrict := true
|
||||||
if this.Config.Get("modeRouterStrict").(bool)==false{
|
if this.Config.Get("modeRouterStrict").(bool) == false {
|
||||||
modeRouterStrict=false
|
modeRouterStrict = false
|
||||||
}
|
}
|
||||||
if router!=nil{
|
if router != nil {
|
||||||
for pk,pv:= range router{
|
for pk, pv := range router {
|
||||||
if !modeRouterStrict{
|
if !modeRouterStrict {
|
||||||
pk=strings.ToLower(pk)
|
pk = strings.ToLower(pk)
|
||||||
}
|
}
|
||||||
if pv!=nil{
|
if pv != nil {
|
||||||
for ck,cv:=range pv{
|
for ck, cv := range pv {
|
||||||
if !modeRouterStrict{
|
if !modeRouterStrict {
|
||||||
ck=strings.ToLower(ck)
|
ck = strings.ToLower(ck)
|
||||||
}
|
}
|
||||||
if cv!=nil{
|
if cv != nil {
|
||||||
for mk,mv:=range cv{
|
for mk, mv := range cv {
|
||||||
if !modeRouterStrict{
|
if !modeRouterStrict {
|
||||||
mk=strings.ToLower(mk)
|
mk = strings.ToLower(mk)
|
||||||
}
|
}
|
||||||
this.MethodRouter["/"+pk+"/"+ck+"/"+mk]=mv
|
this.MethodRouter["/"+pk+"/"+ck+"/"+mk] = mv
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -72,11 +69,10 @@ func (this *Application) Run(router Router) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//this.Port = port
|
//this.Port = port
|
||||||
this.Port = this.Config.GetString("port")
|
this.Port = this.Config.GetString("port")
|
||||||
|
|
||||||
if this.connectDbFunc != nil && (this.Db.DB==nil||this.Db.DB.Ping() != nil) {
|
if this.connectDbFunc != nil && (this.Db.DB == nil || this.Db.DB.Ping() != nil) {
|
||||||
this.Db.SetConnect(this.connectDbFunc)
|
this.Db.SetConnect(this.connectDbFunc)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -168,8 +164,8 @@ func (this *Application) SetConfig(configPath ...string) {
|
|||||||
cmap.JsonToMap(string(btes), &this.Error)
|
cmap.JsonToMap(string(btes), &this.Error)
|
||||||
|
|
||||||
for k, v := range cmap {
|
for k, v := range cmap {
|
||||||
this.Config.Put(k, v)//程序配置
|
this.Config.Put(k, v) //程序配置
|
||||||
Config.Put(k,v)//系统配置
|
Config.Put(k, v) //系统配置
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//else {
|
//else {
|
||||||
@ -239,7 +235,6 @@ func (this *Application) urlSer(url string) (string, []string) {
|
|||||||
|
|
||||||
//访问
|
//访问
|
||||||
|
|
||||||
|
|
||||||
func (this *Application) handler(w http.ResponseWriter, req *http.Request) {
|
func (this *Application) handler(w http.ResponseWriter, req *http.Request) {
|
||||||
|
|
||||||
o, s := this.urlSer(req.RequestURI)
|
o, s := this.urlSer(req.RequestURI)
|
||||||
@ -266,9 +261,9 @@ func (this *Application) handler(w http.ResponseWriter, req *http.Request) {
|
|||||||
sessionId = cookie.Value
|
sessionId = cookie.Value
|
||||||
}
|
}
|
||||||
|
|
||||||
unescapeUrl,err:=url.QueryUnescape(req.RequestURI)
|
unescapeUrl, err := url.QueryUnescape(req.RequestURI)
|
||||||
if err!=nil{
|
if err != nil {
|
||||||
unescapeUrl=req.RequestURI
|
unescapeUrl = req.RequestURI
|
||||||
}
|
}
|
||||||
//访问实例
|
//访问实例
|
||||||
context := Context{SessionIns: SessionIns{SessionId: sessionId,
|
context := Context{SessionIns: SessionIns{SessionId: sessionId,
|
||||||
@ -284,7 +279,6 @@ func (this *Application) handler(w http.ResponseWriter, req *http.Request) {
|
|||||||
//url去掉参数并序列化
|
//url去掉参数并序列化
|
||||||
context.HandlerStr, context.RouterString = this.urlSer(context.HandlerStr)
|
context.HandlerStr, context.RouterString = this.urlSer(context.HandlerStr)
|
||||||
|
|
||||||
|
|
||||||
//访问拦截true继续false暂停
|
//访问拦截true继续false暂停
|
||||||
connectListenerLen := len(this.connectListener)
|
connectListenerLen := len(this.connectListener)
|
||||||
if connectListenerLen != 0 {
|
if connectListenerLen != 0 {
|
||||||
@ -311,14 +305,14 @@ func (this *Application) handler(w http.ResponseWriter, req *http.Request) {
|
|||||||
//
|
//
|
||||||
//}
|
//}
|
||||||
//验证接口严格模式
|
//验证接口严格模式
|
||||||
modeRouterStrict:=this.Config.Get("modeRouterStrict").(bool)
|
modeRouterStrict := this.Config.Get("modeRouterStrict").(bool)
|
||||||
tempHandlerStr:=context.HandlerStr
|
tempHandlerStr := context.HandlerStr
|
||||||
if !modeRouterStrict{
|
if !modeRouterStrict {
|
||||||
tempHandlerStr=strings.ToLower(tempHandlerStr)
|
tempHandlerStr = strings.ToLower(tempHandlerStr)
|
||||||
}
|
}
|
||||||
|
|
||||||
//执行接口
|
//执行接口
|
||||||
if this.MethodRouter[tempHandlerStr]!=nil{
|
if this.MethodRouter[tempHandlerStr] != nil {
|
||||||
this.MethodRouter[tempHandlerStr](&context)
|
this.MethodRouter[tempHandlerStr](&context)
|
||||||
context.View()
|
context.View()
|
||||||
return
|
return
|
||||||
@ -352,11 +346,15 @@ func (this *Application) handler(w http.ResponseWriter, req *http.Request) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//设置header
|
//设置header
|
||||||
delete(header,"Content-Type")
|
delete(header, "Content-Type")
|
||||||
if this.Config.GetInt("debug")!=1{
|
if this.Config.GetInt("debug") != 1 {
|
||||||
header.Set("Cache-Control", "public")
|
header.Set("Cache-Control", "public")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if strings.Index(path, ".m3u8") != -1 {
|
||||||
|
header.Add("Content-Type", "audio/mpegurl")
|
||||||
|
}
|
||||||
|
|
||||||
//w.Write(data)
|
//w.Write(data)
|
||||||
http.ServeFile(w, req, path)
|
http.ServeFile(w, req, path)
|
||||||
|
|
||||||
|
2
mime.go
2
mime.go
@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
package hotime
|
package hotime
|
||||||
|
|
||||||
var MimeMaps = map[string]string{
|
var MimeMaps = map[string]string{
|
||||||
@ -12,6 +11,7 @@ var MimeMaps = map[string]string{
|
|||||||
".abc": "text/vndabc",
|
".abc": "text/vndabc",
|
||||||
".ace": "application/x-ace-compressed",
|
".ace": "application/x-ace-compressed",
|
||||||
".acgi": "text/html",
|
".acgi": "text/html",
|
||||||
|
".m3u8": "audio/mpegurl",
|
||||||
".afl": "video/animaflex",
|
".afl": "video/animaflex",
|
||||||
".ai": "application/postscript",
|
".ai": "application/postscript",
|
||||||
".aif": "audio/aiff",
|
".aif": "audio/aiff",
|
||||||
|
Loading…
Reference in New Issue
Block a user