mirror of
https://github.com/duanhf2012/origin.git
synced 2026-02-27 09:14:44 +08:00
提交文件上传代码
This commit is contained in:
@@ -3,7 +3,7 @@
|
|||||||
"LogLevel":1,
|
"LogLevel":1,
|
||||||
"HttpPort":9400,
|
"HttpPort":9400,
|
||||||
"WSPort":9401,
|
"WSPort":9401,
|
||||||
"ListenPort":9402,
|
"ListenPort":9412,
|
||||||
"CAFile":[
|
"CAFile":[
|
||||||
{
|
{
|
||||||
"CertFile":"",
|
"CertFile":"",
|
||||||
@@ -23,7 +23,7 @@
|
|||||||
"NodeList":[
|
"NodeList":[
|
||||||
{
|
{
|
||||||
"NodeID":1,
|
"NodeID":1,
|
||||||
"NodeAddr": "127.0.0.1:8081",
|
"NodeAddr": "127.0.0.1:8181",
|
||||||
"LogLevel":1,
|
"LogLevel":1,
|
||||||
"HttpPort":7001,
|
"HttpPort":7001,
|
||||||
"WSPort":7000,
|
"WSPort":7000,
|
||||||
|
|||||||
@@ -52,8 +52,6 @@ type InputData struct {
|
|||||||
|
|
||||||
//OnRun ...
|
//OnRun ...
|
||||||
func (ws *SubNet1_Service) OnRun() bool {
|
func (ws *SubNet1_Service) OnRun() bool {
|
||||||
|
|
||||||
|
|
||||||
time.Sleep(time.Second * 10)
|
time.Sleep(time.Second * 10)
|
||||||
var cli network.TcpSocketClient
|
var cli network.TcpSocketClient
|
||||||
cli.Connect("127.0.0.1:9402")
|
cli.Connect("127.0.0.1:9402")
|
||||||
|
|||||||
@@ -33,15 +33,15 @@ func main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//打开Module死循环监控
|
//打开Module死循环监控
|
||||||
node.EnableMonitorModule(time.Second*5)
|
node.EnableMonitorModule(time.Minute*5)
|
||||||
|
originhttp.SetStaticResource(originhttp.METHOD_GET,"/img/","d:/")
|
||||||
nodeCfg, _ := cluster.ReadNodeConfig("./config/nodeconfig.json", cluster.GetNodeId())
|
nodeCfg, _ := cluster.ReadNodeConfig("./config/nodeconfig.json", cluster.GetNodeId())
|
||||||
httpserver := originhttp.NewHttpServerService(nodeCfg.HttpPort) // http服务
|
httpserver := originhttp.NewHttpServerService(nodeCfg.HttpPort) // http服务
|
||||||
for _, ca := range nodeCfg.CAFile {
|
for _, ca := range nodeCfg.CAFile {
|
||||||
httpserver.SetHttps(ca.CertFile, ca.KeyFile)
|
httpserver.SetHttps(ca.CertFile, ca.KeyFile)
|
||||||
}
|
}
|
||||||
|
|
||||||
pTcpService := sysservice.NewTcpSocketPbService(":9402")
|
pTcpService := sysservice.NewTcpSocketPbService(":9412")
|
||||||
pTcpService.SetServiceName("ls")
|
pTcpService.SetServiceName("ls")
|
||||||
/*
|
/*
|
||||||
pTcpService2 := sysservice.NewTcpSocketPbService(":9005")
|
pTcpService2 := sysservice.NewTcpSocketPbService(":9005")
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
@@ -20,6 +21,7 @@ import (
|
|||||||
"github.com/duanhf2012/origin/cluster"
|
"github.com/duanhf2012/origin/cluster"
|
||||||
"github.com/duanhf2012/origin/network"
|
"github.com/duanhf2012/origin/network"
|
||||||
"github.com/duanhf2012/origin/service"
|
"github.com/duanhf2012/origin/service"
|
||||||
|
"github.com/duanhf2012/origin/util/uuid"
|
||||||
)
|
)
|
||||||
|
|
||||||
type HttpRedirectData struct {
|
type HttpRedirectData struct {
|
||||||
@@ -194,6 +196,17 @@ func (slf *HttpServerService) OnInit() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (slf *ServeHTTPRouterMux) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
func (slf *ServeHTTPRouterMux) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
|
if origin := r.Header.Get("Origin"); origin != "" {
|
||||||
|
w.Header().Set("Access-Control-Allow-Origin", "*")
|
||||||
|
w.Header().Set("Access-Control-Allow-Methods", "POST, GET, OPTIONS, PUT, DELETE")
|
||||||
|
w.Header().Set("Access-Control-Allow-Headers",
|
||||||
|
"Action, Module") //有使用自定义头 需要这个,Action, Module是例子
|
||||||
|
}
|
||||||
|
|
||||||
|
if r.Method == "OPTIONS" {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
methodRouter, bok := postAliasUrl[r.Method]
|
methodRouter, bok := postAliasUrl[r.Method]
|
||||||
if bok == false {
|
if bok == false {
|
||||||
writeRespone(w, http.StatusNotFound, fmt.Sprint("Can not support method."))
|
writeRespone(w, http.StatusNotFound, fmt.Sprint("Can not support method."))
|
||||||
@@ -363,8 +376,8 @@ func staticServer(routerUrl string, routerData RouterStaticResoutceData, w http.
|
|||||||
}
|
}
|
||||||
//上传资源
|
//上传资源
|
||||||
case "POST":
|
case "POST":
|
||||||
/*
|
|
||||||
// 在这儿处理例外路由接口
|
// 在这儿处理例外路由接口
|
||||||
|
/*
|
||||||
var errRet error
|
var errRet error
|
||||||
for _, filter := range slf.httpfiltrateList {
|
for _, filter := range slf.httpfiltrateList {
|
||||||
ret := filter(r.URL.Path, w, r)
|
ret := filter(r.URL.Path, w, r)
|
||||||
@@ -378,7 +391,7 @@ func staticServer(routerUrl string, routerData RouterStaticResoutceData, w http.
|
|||||||
if errRet != nil {
|
if errRet != nil {
|
||||||
w.Write([]byte(errRet.Error()))
|
w.Write([]byte(errRet.Error()))
|
||||||
return
|
return
|
||||||
}
|
}*/
|
||||||
r.ParseMultipartForm(32 << 20) // max memory is set to 32MB
|
r.ParseMultipartForm(32 << 20) // max memory is set to 32MB
|
||||||
resourceFile, resourceFileHeader, err := r.FormFile("file")
|
resourceFile, resourceFileHeader, err := r.FormFile("file")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -405,7 +418,7 @@ func staticServer(routerUrl string, routerData RouterStaticResoutceData, w http.
|
|||||||
}
|
}
|
||||||
defer localfd.Close()
|
defer localfd.Close()
|
||||||
io.Copy(localfd, resourceFile)
|
io.Copy(localfd, resourceFile)
|
||||||
writeResp(http.StatusOK, upath+fileName)*/
|
writeResp(http.StatusOK, upath+"/"+fileName)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user