利用go1.16 embed内嵌资源

pull/23/head
taoshihan1991 3 years ago
parent 0aba379949
commit 2a10b36f0f

@ -6,7 +6,7 @@ var GOFLY_LANG={
"chating":"正在与您沟通!",
"historymes":"—— 以上是历史消息 ——",
"moremessage":" 点击加载更多记录",
"copyright":"GO-FLY0.3.8客服陶士涵提供技术支持",
"copyright":"GO-FLY0.3.9客服陶士涵提供技术支持",
"textarea":"请输入内容",
"closemes":"系统自动关闭连接!点击会重连",
"forceclosemes":"客服关闭连接!请重新打开页面",
@ -19,7 +19,7 @@ var GOFLY_LANG={
"chating":"chating with you!",
"historymes":"—— Today ——",
"moremessage":" click buuton show more messages",
"copyright":"We run on GOFLY0.3.8",
"copyright":"We run on GOFLY0.3.9",
"textarea":"Enter your message",
"closemes":"The system automatically closes the connection!",
"forceclosemes":"Admin closes the connection! please reload",

@ -50,7 +50,7 @@ GOFLY.init=function(config){
this.GOFLY_EXTRA.host=document.location.href;
this.GOFLY_EXTRA=JSON.stringify(_this.GOFLY_EXTRA);
this.dynamicLoadJs(this.GOFLY_URL+"/static/js/functions.js?v=1",function(){
this.dynamicLoadJs(this.GOFLY_URL+"/assets/js/functions.js?v=1",function(){
if (typeof config.GOFLY_LANG!="undefined"){
_this.GOFLY_LANG=config.GOFLY_LANG;
}else{

@ -1,6 +1,7 @@
package cmd
import (
"embed"
"github.com/gin-contrib/pprof"
"github.com/gin-gonic/gin"
"github.com/spf13/cobra"
@ -9,7 +10,9 @@ import (
"github.com/taoshihan1991/imaptool/router"
"github.com/taoshihan1991/imaptool/tools"
"github.com/zh-five/xdaemon"
"html/template"
"log"
"net/http"
"os"
)
@ -26,6 +29,12 @@ var serverCmd = &cobra.Command{
},
}
//go:embed templates/*
var templatesEmbed embed.FS
//go:embed js/*
var jsEmbed embed.FS
func init() {
serverCmd.PersistentFlags().StringVarP(&Port, "port", "p", "8081", "监听端口号")
serverCmd.PersistentFlags().BoolVarP(&daemon, "daemon", "d", false, "是否为守护进程模式")
@ -53,7 +62,10 @@ func run() {
tools.Logger().Println("start server...\r\ngohttp://" + baseServer)
engine := gin.Default()
engine.LoadHTMLGlob("static/html/*")
//engine.LoadHTMLGlob("static/html/*")
templ := template.Must(template.New("").ParseFS(templatesEmbed, "templates/*.html"))
engine.SetHTMLTemplate(templ)
engine.StaticFS("/assets", http.FS(jsEmbed))
engine.Static("/static", "./static")
engine.Use(tools.Session("gofly"))
engine.Use(middleware.CrossSite)

@ -6,7 +6,7 @@
<title>GO语言开源客服系统-GOFLY</title>
<link rel="stylesheet" href="/static/css/common.css?v=0.3.8">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/element-ui@2.13.1/lib/theme-chalk/index.css">
<script src="/static/js/functions.js"></script>
<script src="/assets/js/functions.js"></script>
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
<script src="https://cdn.jsdelivr.net/npm/element-ui@2.13.1/lib/index.js"></script>
<script src="https://cdn.jsdelivr.net/npm/jquery/dist/jquery.min.js"></script>
@ -274,5 +274,5 @@
</template>
</div>
</body>
<script src="/static/js/chat-main.js?v=1"></script>
<script src="/assets/js/chat-main.js?v=1"></script>
</html>

@ -7,9 +7,9 @@
<meta name="author" content="陶士涵">
<title>GO语言开源客服系统-GOFLY</title>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/element-ui@2.13.1/lib/theme-chalk/index.css">
<script src="/static/js/functions.js?v=0.1.1"></script>
<script src="/assets/js/functions.js?v=0.1.1"></script>
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
<script src="/static/js/index.js"></script>
<script src="/assets/js/index.js"></script>
<script src="https://cdn.jsdelivr.net/npm/jquery/dist/jquery.min.js"></script>
<!-- Bootstrap core CSS -->
<link rel="stylesheet" href="/static/css/front.css?v=1.0.0" />
@ -90,6 +90,6 @@
var REFER='{{.Refer}}';
var LANG=checkLang();
</script>
<script src="/static/js/chat-lang.js?v=0.3.7"></script>
<script src="/static/js/chat-page.js?v=0.3.7"></script>
<script src="/assets/js/chat-lang.js?v=0.3.7"></script>
<script src="/assets/js/chat-page.js?v=0.3.7"></script>
</html>

@ -20,7 +20,7 @@
</head>
<body>
<!--对接客服代码,安装完成后更改成自己的域名或IP下面js文件路径以及GOFLY_URL都要改-->
<script src="https://jd.sopans.com/static/js/gofly-front.js?v=1"></script>
<script src="https://jd.sopans.com/assets/js/gofly-front.js?v=1"></script>
<script>
GOFLY.init({
GOFLY_URL:"https://jd.sopans.com",
@ -78,7 +78,7 @@
<div class="productContent">
<p>1.引入js并且修改为自己的域名</p>
<pre>
script标签引入这段js https://gofly.sopans.com/static/js/gofly-front.js
script标签引入这段js https://gofly.sopans.com/assets/js/gofly-front.js
GOFLY.init({
GOFLY_URL:"https://gofly.sopans.com",
GOFLY_KEFU_ID: "kefu2",//对接的客服name

@ -10,7 +10,7 @@
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
<script src="https://cdn.jsdelivr.net/npm/element-ui@2.13.1/lib/index.js"></script>
<script src="https://cdn.jsdelivr.net/npm/jquery/dist/jquery.min.js"></script>
<script src="/static/js/functions.js"></script>
<script src="/assets/js/functions.js"></script>
<style>
html,
body {

@ -13,7 +13,7 @@
effect="dark">
</el-alert>
<textarea style="width:100%;color:green;margin-top:10px;font-size:12px;height:290px;">
<script src="https://gofly.sopans.com/static/js/gofly-front.js"></script>
<script src="https://gofly.sopans.com/assets/js/gofly-front.js"></script>
<script>
GOFLY.init({
GOFLY_URL:"https://gofly.sopans.com",

@ -31,7 +31,7 @@
</body>
{{template "setting_bottom" .}}
<!--对接客服代码,安装完成后更改成自己的域名或IP下面js文件路径以及GOFLY_URL都要改-->
<script src="https://gofly.sopans.com/static/js/gofly-front.js?v=1"></script>
<script src="https://gofly.sopans.com/assets/js/gofly-front.js?v=1"></script>
<script>
GOFLY.init({
GOFLY_URL:"https://gofly.sopans.com",

@ -150,7 +150,7 @@ INSERT INTO `about` (`id`, `title_cn`, `title_en`, `keywords_cn`, `keywords_en`,
'一款开箱即用的在线客服系统',
'a free customer live chat',
'<style>body{color: #333;padding-left: 40px;}h1{font-size: 6em;}h2{font-size: 3em;font-weight: normal;}a{color: #333;}</style>',
'<script src="/static/js/gofly-front.js?v=1"></script><script>
'<script src="/assets/js/gofly-front.js?v=1"></script><script>
GOFLY.init({
GOFLY_URL:"",
GOFLY_KEFU_ID: "kefu2",
@ -159,7 +159,7 @@ INSERT INTO `about` (`id`, `title_cn`, `title_en`, `keywords_cn`, `keywords_en`,
})
</script>
<h1>:)</h1><h2> <a href="https://gofly.sopans.com">GOFLY0.3.9</a> 线 !</h2><h3><a href="/login">Administrator</a>&nbsp;<a href="/index_en">English</a>&nbsp;<a href="/index_cn"></a></h3>',
'<script src="/static/js/gofly-front.js?v=1"></script><script>
'<script src="/assets/js/gofly-front.js?v=1"></script><script>
GOFLY.init({
GOFLY_URL:"",
GOFLY_KEFU_ID: "kefu2",

@ -1,6 +1,6 @@
module github.com/taoshihan1991/imaptool
go 1.14
go 1.16
require (
github.com/dchest/captcha v0.0.0-20200903113550-03f5f0333e1f

@ -113,7 +113,7 @@
```php
//下面js路径和GOFLY_URL 都要改成自己的
<script src="https://gofly.sopans.com/static/js/gofly-front.js"></script>
<script src="https://gofly.sopans.com/assets/js/gofly-front.js"></script>
<script>
GOFLY.init({
GOFLY_URL:"https://gofly.sopans.com",
@ -239,6 +239,15 @@ location /
```
### 更新日志
##### V0.3.8
访客端输入框以及图标icon按钮修改
客服端界面icon修改
修复后端发消息空指针错误导致的进程退出
增加允许跨域的http头,nginx中的跨域相关http头可以去掉
##### V0.3.7

Loading…
Cancel
Save