This commit is contained in:
hoteas 2017-09-05 08:45:02 +00:00
parent 1c2e7007df
commit 497d78ab4e
4 changed files with 311 additions and 130 deletions

View File

@ -5,9 +5,14 @@
</component> </component>
<component name="ChangeListManager"> <component name="ChangeListManager">
<list default="true" readonly="true" id="03ed5703-81a1-441b-849c-c426276586b7" name="Default" comment=""> <list default="true" readonly="true" id="03ed5703-81a1-441b-849c-c426276586b7" name="Default" comment="">
<change type="NEW" beforePath="" afterPath="$PROJECT_DIR$/dri" />
<change type="NEW" beforePath="" afterPath="$PROJECT_DIR$/dri/ddsms" />
<change type="NEW" beforePath="" afterPath="$PROJECT_DIR$/dri/upload" />
<change type="NEW" beforePath="" afterPath="$PROJECT_DIR$/dri/ddsms/ddsms.go" />
<change type="NEW" beforePath="" afterPath="$PROJECT_DIR$/dri/upload/upload.go" />
<change type="DELETED" beforePath="$PROJECT_DIR$/config/config.json" afterPath="" />
<change type="DELETED" beforePath="$PROJECT_DIR$/config" afterPath="" />
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/.idea/workspace.xml" afterPath="$PROJECT_DIR$/.idea/workspace.xml" /> <change type="MODIFICATION" beforePath="$PROJECT_DIR$/.idea/workspace.xml" afterPath="$PROJECT_DIR$/.idea/workspace.xml" />
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/map.go" afterPath="$PROJECT_DIR$/map.go" />
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/slice.go" afterPath="$PROJECT_DIR$/slice.go" />
</list> </list>
<ignored path=".idea/dataSources.local.xml" /> <ignored path=".idea/dataSources.local.xml" />
<option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" /> <option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" />
@ -38,6 +43,16 @@
</provider> </provider>
</entry> </entry>
</file> </file>
<file leaf-file-name="func.go" pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/func.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="-255">
<caret line="21" column="5" lean-forward="false" selection-start-line="21" selection-start-column="5" selection-end-line="21" selection-end-column="5" />
<folding />
</state>
</provider>
</entry>
</file>
<file leaf-file-name="obj.go" pinned="false" current-in-tab="false"> <file leaf-file-name="obj.go" pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/obj.go"> <entry file="file://$PROJECT_DIR$/obj.go">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
@ -48,23 +63,43 @@
</provider> </provider>
</entry> </entry>
</file> </file>
<file leaf-file-name="main.go" pinned="false" current-in-tab="false"> <file leaf-file-name="manage.go" pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/example/main.go"> <entry file="file://$PROJECT_DIR$/manage/manage.go">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="1210"> <state relative-caret-position="510">
<caret line="85" column="0" lean-forward="true" selection-start-line="85" selection-start-column="0" selection-end-line="85" selection-end-column="0" /> <caret line="39" column="9" lean-forward="false" selection-start-line="39" selection-start-column="9" selection-end-line="39" selection-end-column="9" />
<folding />
</state>
</provider>
</entry>
</file>
<file leaf-file-name="ddsms.go" pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/dri/ddsms/ddsms.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="1292">
<caret line="83" column="22" lean-forward="true" selection-start-line="83" selection-start-column="22" selection-end-line="83" selection-end-column="22" />
<folding />
</state>
</provider>
</entry>
</file>
<file leaf-file-name="upload.go" pinned="false" current-in-tab="true">
<entry file="file://$PROJECT_DIR$/dri/upload/upload.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="1173">
<caret line="69" column="1" lean-forward="true" selection-start-line="69" selection-start-column="1" selection-end-line="69" selection-end-column="1" />
<folding> <folding>
<element signature="e#14#137#0" expanded="true" /> <element signature="e#16#121#0" expanded="true" />
</folding> </folding>
</state> </state>
</provider> </provider>
</entry> </entry>
</file> </file>
<file leaf-file-name="fd_mutex.go" pinned="false" current-in-tab="false"> <file leaf-file-name="config.json" pinned="false" current-in-tab="false">
<entry file="file://D:/app/go/src/internal/poll/fd_mutex.go"> <entry file="file://$PROJECT_DIR$/example/config/config.json">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="272"> <state relative-caret-position="289">
<caret line="236" column="0" lean-forward="false" selection-start-line="236" selection-start-column="0" selection-end-line="236" selection-end-column="0" /> <caret line="17" column="1" lean-forward="false" selection-start-line="17" selection-start-column="1" selection-end-line="17" selection-end-column="1" />
<folding /> <folding />
</state> </state>
</provider> </provider>
@ -80,16 +115,6 @@
</provider> </provider>
</entry> </entry>
</file> </file>
<file leaf-file-name="context_base.go" pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/context_base.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="153">
<caret line="9" column="0" lean-forward="false" selection-start-line="9" selection-start-column="0" selection-end-line="16" selection-end-column="1" />
<folding />
</state>
</provider>
</entry>
</file>
<file leaf-file-name="session.go" pinned="false" current-in-tab="false"> <file leaf-file-name="session.go" pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/session.go"> <entry file="file://$PROJECT_DIR$/session.go">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
@ -100,11 +125,11 @@
</provider> </provider>
</entry> </entry>
</file> </file>
<file leaf-file-name="slice.go" pinned="false" current-in-tab="true"> <file leaf-file-name="slice.go" pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/slice.go"> <entry file="file://$PROJECT_DIR$/slice.go">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="272"> <state relative-caret-position="544">
<caret line="16" column="0" lean-forward="true" selection-start-line="16" selection-start-column="0" selection-end-line="16" selection-end-column="0" /> <caret line="32" column="42" lean-forward="false" selection-start-line="32" selection-start-column="42" selection-end-line="32" selection-end-column="42" />
<folding> <folding>
<element signature="e#16#53#0" expanded="true" /> <element signature="e#16#53#0" expanded="true" />
</folding> </folding>
@ -112,26 +137,6 @@
</provider> </provider>
</entry> </entry>
</file> </file>
<file leaf-file-name="cache_db.go" pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/cache_db.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="-289">
<caret line="10" column="15" lean-forward="false" selection-start-line="10" selection-start-column="15" selection-end-line="10" selection-end-column="15" />
<folding />
</state>
</provider>
</entry>
</file>
<file leaf-file-name="cache_memory.go" pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/cache_memory.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="816">
<caret line="92" column="1" lean-forward="false" selection-start-line="92" selection-start-column="1" selection-end-line="92" selection-end-column="1" />
<folding />
</state>
</provider>
</entry>
</file>
</leaf> </leaf>
</component> </component>
<component name="FileTemplateManagerImpl"> <component name="FileTemplateManagerImpl">
@ -187,6 +192,7 @@
<option value="$PROJECT_DIR$/example/main.go" /> <option value="$PROJECT_DIR$/example/main.go" />
<option value="$PROJECT_DIR$/map.go" /> <option value="$PROJECT_DIR$/map.go" />
<option value="$PROJECT_DIR$/slice.go" /> <option value="$PROJECT_DIR$/slice.go" />
<option value="$PROJECT_DIR$/dri/upload/upload.go" />
</list> </list>
</option> </option>
</component> </component>
@ -244,7 +250,29 @@
<option name="myItemType" value="com.jetbrains.php.projectView.PhpTreeStructureProvider$1" /> <option name="myItemType" value="com.jetbrains.php.projectView.PhpTreeStructureProvider$1" />
</PATH_ELEMENT> </PATH_ELEMENT>
<PATH_ELEMENT> <PATH_ELEMENT>
<option name="myItemId" value="example" /> <option name="myItemId" value="dri" />
<option name="myItemType" value="com.jetbrains.php.projectView.PhpTreeStructureProvider$1" />
</PATH_ELEMENT>
<PATH_ELEMENT>
<option name="myItemId" value="upload" />
<option name="myItemType" value="com.jetbrains.php.projectView.PhpTreeStructureProvider$1" />
</PATH_ELEMENT>
</PATH>
<PATH>
<PATH_ELEMENT>
<option name="myItemId" value="hotime" />
<option name="myItemType" value="com.intellij.ide.projectView.impl.nodes.ProjectViewProjectNode" />
</PATH_ELEMENT>
<PATH_ELEMENT>
<option name="myItemId" value="hotime" />
<option name="myItemType" value="com.jetbrains.php.projectView.PhpTreeStructureProvider$1" />
</PATH_ELEMENT>
<PATH_ELEMENT>
<option name="myItemId" value="dri" />
<option name="myItemType" value="com.jetbrains.php.projectView.PhpTreeStructureProvider$1" />
</PATH_ELEMENT>
<PATH_ELEMENT>
<option name="myItemId" value="ddsms" />
<option name="myItemType" value="com.jetbrains.php.projectView.PhpTreeStructureProvider$1" /> <option name="myItemType" value="com.jetbrains.php.projectView.PhpTreeStructureProvider$1" />
</PATH_ELEMENT> </PATH_ELEMENT>
</PATH> </PATH>
@ -265,12 +293,13 @@
<property name="DefaultHtmlFileTemplate" value="HTML File" /> <property name="DefaultHtmlFileTemplate" value="HTML File" />
</component> </component>
<component name="RecentsManager"> <component name="RecentsManager">
<key name="CopyFile.RECENT_KEYS">
<recent name="E:\gopath1\trunk\src\go.hoteas.com\hotime\dri" />
<recent name="D:\golang\path\trunk\src\hoteas\hotime" />
</key>
<key name="MoveFile.RECENT_KEYS"> <key name="MoveFile.RECENT_KEYS">
<recent name="E:\gopath1\trunk\src\go.hoteas.com\hotime\example" /> <recent name="E:\gopath1\trunk\src\go.hoteas.com\hotime\example" />
</key> </key>
<key name="CopyFile.RECENT_KEYS">
<recent name="D:\golang\path\trunk\src\hoteas\hotime" />
</key>
</component> </component>
<component name="RunDashboard"> <component name="RunDashboard">
<option name="ruleStates"> <option name="ruleStates">
@ -452,7 +481,7 @@
<workItem from="1504252839700" duration="18000" /> <workItem from="1504252839700" duration="18000" />
<workItem from="1504488004086" duration="365000" /> <workItem from="1504488004086" duration="365000" />
<workItem from="1504488391347" duration="840000" /> <workItem from="1504488391347" duration="840000" />
<workItem from="1504575702799" duration="8135000" /> <workItem from="1504575702799" duration="10681000" />
</task> </task>
<task id="LOCAL-00001"> <task id="LOCAL-00001">
<created>1500458878821</created> <created>1500458878821</created>
@ -622,11 +651,18 @@
<option name="project" value="LOCAL" /> <option name="project" value="LOCAL" />
<updated>1504580975118</updated> <updated>1504580975118</updated>
</task> </task>
<option name="localTasksCounter" value="25" /> <task id="LOCAL-00025" summary="管理端初步">
<created>1504596978308</created>
<option name="number" value="00025" />
<option name="presentableId" value="LOCAL-00025" />
<option name="project" value="LOCAL" />
<updated>1504596978308</updated>
</task>
<option name="localTasksCounter" value="26" />
<servers /> <servers />
</component> </component>
<component name="TimeTrackingManager"> <component name="TimeTrackingManager">
<option name="totallyTimeSpent" value="85673000" /> <option name="totallyTimeSpent" value="88219000" />
</component> </component>
<component name="TodoView"> <component name="TodoView">
<todo-panel id="selected-file"> <todo-panel id="selected-file">
@ -674,7 +710,8 @@
<MESSAGE value="框架基本完成" /> <MESSAGE value="框架基本完成" />
<MESSAGE value="demo" /> <MESSAGE value="demo" />
<MESSAGE value="管理端初步" /> <MESSAGE value="管理端初步" />
<option name="LAST_COMMIT_MESSAGE" value="管理端初步" /> <MESSAGE value="工具" />
<option name="LAST_COMMIT_MESSAGE" value="工具" />
</component> </component>
<component name="XDebuggerManager"> <component name="XDebuggerManager">
<breakpoint-manager> <breakpoint-manager>
@ -683,20 +720,6 @@
<watches-manager /> <watches-manager />
</component> </component>
<component name="editorHistoryManager"> <component name="editorHistoryManager">
<entry file="file://$PROJECT_DIR$/db.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="-289">
<caret line="1" column="2" lean-forward="false" selection-start-line="1" selection-start-column="2" selection-end-line="1" selection-end-column="2" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/slice.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="678">
<caret line="69" column="0" lean-forward="false" selection-start-line="69" selection-start-column="0" selection-end-line="69" selection-end-column="0" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/error.go"> <entry file="file://$PROJECT_DIR$/error.go">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="255"> <state relative-caret-position="255">
@ -803,20 +826,6 @@
</state> </state>
</provider> </provider>
</entry> </entry>
<entry file="file://$PROJECT_DIR$/func.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="357">
<caret line="21" column="5" lean-forward="false" selection-start-line="21" selection-start-column="5" selection-end-line="21" selection-end-column="5" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/example/config/config.json">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="289">
<caret line="17" column="1" lean-forward="false" selection-start-line="17" selection-start-column="1" selection-end-line="17" selection-end-column="1" />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/application.go"> <entry file="file://$PROJECT_DIR$/application.go">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="102"> <state relative-caret-position="102">
@ -927,24 +936,6 @@
</state> </state>
</provider> </provider>
</entry> </entry>
<entry file="file://$PROJECT_DIR$/manage/manage.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="510">
<caret line="39" column="9" lean-forward="false" selection-start-line="39" selection-start-column="9" selection-end-line="39" selection-end-column="9" />
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/config/config.json">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="289">
<caret line="18" column="1" lean-forward="true" selection-start-line="18" selection-start-column="1" selection-end-line="18" selection-end-column="1" />
<folding>
<marker date="1504580963456" expanded="true" signature="201:235" ph="[...]" />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/var.go"> <entry file="file://$PROJECT_DIR$/var.go">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="306"> <state relative-caret-position="306">
@ -988,7 +979,7 @@
<entry file="file://$PROJECT_DIR$/example/main.go"> <entry file="file://$PROJECT_DIR$/example/main.go">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="1210"> <state relative-caret-position="1210">
<caret line="85" column="0" lean-forward="true" selection-start-line="85" selection-start-column="0" selection-end-line="85" selection-end-column="0" /> <caret line="85" column="0" lean-forward="false" selection-start-line="85" selection-start-column="0" selection-end-line="85" selection-end-column="0" />
<folding> <folding>
<element signature="e#14#137#0" expanded="true" /> <element signature="e#14#137#0" expanded="true" />
</folding> </folding>
@ -1003,16 +994,6 @@
</state> </state>
</provider> </provider>
</entry> </entry>
<entry file="file://$PROJECT_DIR$/map.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="315">
<caret line="49" column="0" lean-forward="false" selection-start-line="49" selection-start-column="0" selection-end-line="58" selection-end-column="1" />
<folding>
<element signature="e#16#72#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/obj.go"> <entry file="file://$PROJECT_DIR$/obj.go">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="85"> <state relative-caret-position="85">
@ -1039,13 +1020,73 @@
</entry> </entry>
<entry file="file://$PROJECT_DIR$/slice.go"> <entry file="file://$PROJECT_DIR$/slice.go">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="272"> <state relative-caret-position="544">
<caret line="16" column="0" lean-forward="true" selection-start-line="16" selection-start-column="0" selection-end-line="16" selection-end-column="0" /> <caret line="32" column="42" lean-forward="false" selection-start-line="32" selection-start-column="42" selection-end-line="32" selection-end-column="42" />
<folding> <folding>
<element signature="e#16#53#0" expanded="true" /> <element signature="e#16#53#0" expanded="true" />
</folding> </folding>
</state> </state>
</provider> </provider>
</entry> </entry>
<entry file="file://$PROJECT_DIR$/map.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="315">
<caret line="49" column="0" lean-forward="false" selection-start-line="49" selection-start-column="0" selection-end-line="58" selection-end-column="1" />
<folding>
<element signature="e#16#72#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/func.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="-255">
<caret line="21" column="5" lean-forward="false" selection-start-line="21" selection-start-column="5" selection-end-line="21" selection-end-column="5" />
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/manage/manage.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="510">
<caret line="39" column="9" lean-forward="false" selection-start-line="39" selection-start-column="9" selection-end-line="39" selection-end-column="9" />
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/config/config.json">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="306">
<caret line="18" column="1" lean-forward="true" selection-start-line="18" selection-start-column="1" selection-end-line="18" selection-end-column="1" />
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/example/config/config.json">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="289">
<caret line="17" column="1" lean-forward="false" selection-start-line="17" selection-start-column="1" selection-end-line="17" selection-end-column="1" />
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/dri/ddsms/ddsms.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="1292">
<caret line="83" column="22" lean-forward="true" selection-start-line="83" selection-start-column="22" selection-end-line="83" selection-end-column="22" />
<folding />
</state>
</provider>
</entry>
<entry file="file://$PROJECT_DIR$/dri/upload/upload.go">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="1173">
<caret line="69" column="1" lean-forward="true" selection-start-line="69" selection-start-column="1" selection-end-line="69" selection-end-column="1" />
<folding>
<element signature="e#16#121#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
</component> </component>
</project> </project>

View File

@ -1,19 +0,0 @@
{
"HOTIME-MAP": 1504577466932974800,
"cacheLongTime": 2592000,
"cacheShortTime": 7200,
"dbHost": "127.0.0.1",
"dbName": "test",
"dbPort": "3306",
"dbPwd": "root",
"dbUser": "root",
"defFile": [
"index.html",
"index.htm"
],
"error": {},
"logLevel": 0,
"port": "80",
"sessionName": "HOTIME",
"tpt": "tpt"
}

89
dri/ddsms/ddsms.go Normal file
View File

@ -0,0 +1,89 @@
package ddsms
import (
"encoding/json"
"errors"
"io/ioutil"
"net/http"
"net/url"
"strings"
)
type DDY struct {
ApiKey string
YzmUrl string
TzUrl string
}
func (this *DDY) Init(apikey string, uzmurl string, tzurl string) {
this.ApiKey = apikey
this.YzmUrl = uzmurl
this.TzUrl = tzurl
}
//发送短信验证码 code验证码如123456 返回true表示发送成功flase表示发送失败
func (this *DDY) SendYZM(umoblie string, tpt string, data map[string]string) (bool, error) {
for k, v := range data {
tpt = strings.Replace(tpt, "{"+k+"}", v, -1)
}
return this.send(this.YzmUrl, umoblie, tpt)
}
//发送通知
func (this *DDY) SendTz(umoblie []string, tpt string, data map[string]string) (bool, error) {
for k, v := range data {
tpt = strings.Replace(tpt, "["+k+"]", v, -1)
}
umobleStr := ""
for i, v := range umoblie {
if i == 0 {
umobleStr = v
continue
}
umobleStr += "," + v
}
return this.send(this.TzUrl, umobleStr, tpt)
}
//发送短信
func (this *DDY) send(mUrl string, umoblie string, content string) (bool, error) {
data_send_sms_yzm := url.Values{"apikey": {this.ApiKey}, "mobile": {umoblie}, "content": {content}}
res, err := this.httpsPostForm(mUrl, data_send_sms_yzm)
if err != nil && res == "" {
return false, errors.New("连接错误")
}
var msg interface{}
err1 := json.Unmarshal([]byte(res), &msg)
if err1 != nil {
return false, errors.New("json解析错误")
}
resmsg := msg.(map[string]interface{})
rcode := int(resmsg["code"].(float64))
result := resmsg["msg"].(string)
if rcode != 1 {
return false, errors.New(result)
}
return true, nil
}
//调用url发送短信的连接
func (this *DDY) httpsPostForm(url string, data url.Values) (string, error) {
resp, err := http.PostForm(url, data)
if err != nil {
return "", err
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
return "", err
}
return string(body), nil
}

70
dri/upload/upload.go Normal file
View File

@ -0,0 +1,70 @@
package upload
import (
"errors"
"go.hoteas.com/hotime"
"io"
"mime/multipart"
"net/http"
"os"
"strings"
"time"
)
type Upload struct {
Path string
}
func (this *Upload) UpFile(Request *http.Request, fieldName, savefilepath, savePath string) (string, error) {
Request.ParseMultipartForm(32 << 20)
var filePath string
files := Request.MultipartForm.File
var file multipart.File
err := errors.New("")
for k, _ := range files {
fieldName = k
file, _, err = Request.FormFile(fieldName)
if err != nil {
return "", errors.New("上传头像失败")
}
}
if strings.EqualFold(savePath, "") {
t := time.Now().Unix()
data := time.Unix(int64(t), 0).Format("2006-01")
path := ""
if strings.EqualFold(savefilepath, "") {
path = this.Path + data
} else {
path = savefilepath + data
}
_, err1 := os.Stat(path)
if err1 != nil {
if os.IsNotExist(err1) {
err := os.MkdirAll(path, os.ModePerm)
if err != nil {
return "", errors.New("服务器创建头像文件夹失败")
}
}
}
filename := time.Unix(int64(t), 0).Format("2006-01-02-15-22-25") + hotime.ObjToStr(hotime.Rand(6))
filePath = path + "/" + filename + this.Path
} else {
filePath = savePath
}
header, err := os.OpenFile(filePath, os.O_CREATE, 0666)
if err != nil {
return "", errors.New("服务器创建头像文件失败")
}
_, err = io.Copy(header, file)
if err != nil {
return "", errors.New("服务器复制头像文件失败")
}
return filePath, nil
}