Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
energye
energy
提交
2fc7a31c
energy
项目概览
energye
/
energy
通知
13
Star
2
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
energy
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
2fc7a31c
编写于
11月 23, 2022
作者:
yanghye
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
demo: add go-bind-js-var
上级
586e07a3
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
183 addition
and
1 deletion
+183
-1
example/browser-execute-javascript/resources/execute-javascript.html
...wser-execute-javascript/resources/execute-javascript.html
+1
-1
example/browser-go-bind-js-var/go-bind-js-var.go
example/browser-go-bind-js-var/go-bind-js-var.go
+43
-0
example/browser-go-bind-js-var/libs/liblcl.dll存放目录-可内置到执行程序中.md
...e/browser-go-bind-js-var/libs/liblcl.dll存放目录-可内置到执行程序中.md
+4
-0
example/browser-go-bind-js-var/resources/go-bind-js-var.html
example/browser-go-bind-js-var/resources/go-bind-js-var.html
+97
-0
example/browser-go-bind-js-var/resources/icon.ico
example/browser-go-bind-js-var/resources/icon.ico
+0
-0
example/browser-go-bind-js-var/resources/资源存放目录-可内置到执行程序中.md
example/browser-go-bind-js-var/resources/资源存放目录-可内置到执行程序中.md
+4
-0
example/browser-go-bind-js-var/src/common-var.go
example/browser-go-bind-js-var/src/common-var.go
+1
-0
example/browser-go-bind-js-var/src/struct-var.go
example/browser-go-bind-js-var/src/struct-var.go
+33
-0
未找到文件。
example/browser-execute-javascript/resources/execute-javascript.html
浏览文件 @
2fc7a31c
...
...
@@ -6,7 +6,7 @@
<script
type=
"application/javascript"
>
function
GoExecuteJSFunc
(
param
,
param1
)
{
let
message
=
document
.
getElementById
(
"
message
"
);
message
.
innerHTML
=
message
.
innerHTML
+
param
+
"
"
+
param1
+
"
<br>
"
message
.
innerHTML
=
message
.
innerHTML
+
"
param0:
"
+
param
+
"
param1:
"
+
param1
+
"
<br>
"
if
(
param
%
2
===
0
)
{
message
.
style
.
color
=
"
red
"
}
else
{
...
...
example/browser-go-bind-js-var/go-bind-js-var.go
0 → 100644
浏览文件 @
2fc7a31c
package
main
import
(
"embed"
"fmt"
"github.com/energye/energy/cef"
"github.com/energye/energy/common/assetserve"
"github.com/energye/energy/example/browser-go-bind-js-var/src"
)
//go:embed resources
var
resources
embed
.
FS
func
main
()
{
//全局初始化 每个应用都必须调用的
cef
.
GlobalCEFInit
(
nil
,
&
resources
)
//创建应用
cefApp
:=
cef
.
NewApplication
(
nil
)
//指定一个URL地址,或本地html文件目录
cef
.
BrowserWindow
.
Config
.
DefaultUrl
=
"http://localhost:22022/go-bind-js-var.html"
cef
.
BrowserWindow
.
Config
.
Title
=
"Energy - execute-javascript"
cef
.
BrowserWindow
.
Config
.
Icon
=
"resources/icon.ico"
//内置http服务链接安全配置
cef
.
SetBrowserProcessStartAfterCallback
(
func
(
b
bool
)
{
fmt
.
Println
(
"主进程启动 创建一个内置http服务"
)
//通过内置http服务加载资源
server
:=
assetserve
.
NewAssetsHttpServer
()
server
.
PORT
=
22022
server
.
AssetsFSName
=
"resources"
//必须设置目录名
server
.
Assets
=
&
resources
go
server
.
StartHttpServer
()
})
//变量创建回调-这个函数在主进程(browser)和子进程(render)中执行
//变量的值绑定到主进程
cef
.
VariableBind
.
VariableCreateCallback
(
func
(
browser
*
cef
.
ICefBrowser
,
frame
*
cef
.
ICefFrame
,
bind
cef
.
IProvisionalBindStorage
)
{
//初始化要绑定的变量
src
.
JSStructVarDemo
=
&
src
.
StructVarDemo
{}
src
.
JSStructVarDemo
.
StringField
=
"初始的字符串值"
bind
.
NewObjects
(
src
.
JSStructVarDemo
)
})
//运行应用
cef
.
Run
(
cefApp
)
}
example/browser-go-bind-js-var/libs/liblcl.dll存放目录-可内置到执行程序中.md
0 → 100644
浏览文件 @
2fc7a31c
提取Energy压缩包动态链接库liblcl.dll到该目录下
libs目录下的文件会被编译到执行文件中
\ No newline at end of file
example/browser-go-bind-js-var/resources/go-bind-js-var.html
0 → 100644
浏览文件 @
2fc7a31c
<!DOCTYPE html>
<html
lang=
"en"
>
<head>
<meta
charset=
"UTF-8"
>
<title>
execute-go-bind-js-var
</title>
<script
type=
"application/javascript"
>
function
clearMessage
()
{
document
.
getElementById
(
"
message
"
).
innerHTML
=
""
;
}
function
writeMessage
(
data
)
{
let
message
=
document
.
getElementById
(
"
message
"
);
message
.
innerHTML
=
message
.
innerHTML
+
data
+
"
<br>
"
}
//通过根对象 goobj 和 gocobj 获取或设置值
//goobj 是结构类型的根对象
//gocobj 是普通类型的根对象
/** 结构类型 */
//获取Go中定义的绑定变量值
function
getGoBindVar
()
{
clearMessage
()
writeMessage
(
"
结构
"
)
//------------------------
//获取结构类型的字段值 string
writeMessage
(
"
StringField:
"
+
goobj
.
StructVarDemo
.
StringField
)
writeMessage
(
"
IntField:
"
+
goobj
.
StructVarDemo
.
IntField
)
writeMessage
(
"
BoolField:
"
+
goobj
.
StructVarDemo
.
BoolField
)
writeMessage
(
"
FloatField:
"
+
goobj
.
StructVarDemo
.
FloatField
)
try
{
writeMessage
(
"
noExportField 是未导出的字段,将获取失败
"
)
writeMessage
(
"
noExportField:
"
+
goobj
.
StructVarDemo
.
noExportField
)
}
catch
(
e
)
{
writeMessage
(
"
异常:
"
+
e
)
}
}
//设置Go中定义的绑定变量值
function
setGoBindVar
()
{
clearMessage
()
writeMessage
(
"
结构
"
)
//设置结构类型的字段值 string
//注意: 结构类型的字段,设置不同类型的值将出现JS异常
goobj
.
StructVarDemo
.
StringField
=
"
在Web中改变后的值
"
goobj
.
StructVarDemo
.
IntField
=
999999
goobj
.
StructVarDemo
.
BoolField
=
true
goobj
.
StructVarDemo
.
FloatField
=
99999.9999
try
{
writeMessage
(
"
StringField=int 不同的类型赋值将出现异常
"
)
//不同的类型赋值将出现异常
goobj
.
StructVarDemo
.
StringField
=
1001
}
catch
(
e
)
{
writeMessage
(
"
异常:
"
+
e
)
}
}
//调用Go中定义的函数
function
callGoBindFunc
()
{
clearMessage
()
writeMessage
(
"
结构
"
)
//在JS中调用Go的函数
//注意:同字段一样函数首字母只有大写才能调用
// 入参类型必须符合Go中函数定义的参数类型, 否则调用失败, 注意的是参数个数有限制
let
ret
=
goobj
.
StructVarDemo
.
StringValue
(
'
JS传的入参
'
)
writeMessage
(
"
调用函数 StringValue(param0 string) string:
"
+
ret
)
goobj
.
StructVarDemo
.
FuncMaxParam
(
'
参数1
'
,
'
参数2
'
,
'
参数3
'
,
'
参数4
'
,
'
参数5
'
,
'
参数6
'
,
'
参数7
'
,
'
参数8
'
,
'
参数9
'
)
try
{
writeMessage
(
"
FuncMaxParam 函数和入参个数大于9个调用失败
"
)
//参数个数大于9个调用失败
goobj
.
StructVarDemo
.
FuncMaxParam
(
'
参数1
'
,
'
参数2
'
,
'
参数3
'
,
'
参数4
'
,
'
参数5
'
,
'
参数6
'
,
'
参数7
'
,
'
参数8
'
,
'
参数9
'
,
'
参数10
'
)
}
catch
(
e
)
{
writeMessage
(
"
异常:
"
+
e
)
}
}
/** 普通类型 */
</script>
</head>
<body
style=
"overflow: hidden;margin: 0px;padding: 0px;"
>
execute-go-bind-js-var:
<br>
<div
style=
"margin: 10px"
>
结构类型:
<button
onclick=
"getGoBindVar()"
>
获取Go中定义的绑定变量值
</button>
<button
onclick=
"setGoBindVar()"
>
设置Go中定义的绑定变量值
</button>
<button
onclick=
"callGoBindFunc()"
>
调用Go中定义的函数
</button>
</div>
<div
style=
"margin: 10px"
>
普通类型:
<button
onclick=
"getGoBindVar()"
>
获取Go中定义的绑定变量值
</button>
<button
onclick=
"setGoBindVar()"
>
设置Go中定义的绑定变量值
</button>
</div>
<div
id=
"message"
>
</div>
</body>
</html>
\ No newline at end of file
example/browser-go-bind-js-var/resources/icon.ico
0 → 100644
浏览文件 @
2fc7a31c
66.1 KB
example/browser-go-bind-js-var/resources/资源存放目录-可内置到执行程序中.md
0 → 100644
浏览文件 @
2fc7a31c
可将html css javascript image等静态资源放入该目录,编译后将内置到执行程序中
通过内置http server 读取该目录文件,展示到页面中
\ No newline at end of file
example/browser-go-bind-js-var/src/common-var.go
0 → 100644
浏览文件 @
2fc7a31c
package
src
example/browser-go-bind-js-var/src/struct-var.go
0 → 100644
浏览文件 @
2fc7a31c
package
src
import
"fmt"
var
JSStructVarDemo
*
StructVarDemo
//定义结构类型的变量
//结构类型将属性和函数导出为JS可调用类型
//大写字母开头
type
StructVarDemo
struct
{
StringField
string
IntField
int32
BoolField
bool
FloatField
float64
noExportField
string
//小写字母无法绑定到js
}
//结构类型的函数导出
func
(
m
*
StructVarDemo
)
StringValue
(
p0
string
)
string
{
fmt
.
Println
(
"结构类型绑定函数 StringValue 被调用 入参:"
,
p0
)
return
m
.
StringField
+
p0
}
//结构类型的函数导出
func
(
m
*
StructVarDemo
)
IntValue
(
intParam
int32
)
int32
{
fmt
.
Println
(
"结构类型绑定函数 IntValue 被调用 入参:"
,
intParam
)
return
m
.
IntField
+
intParam
}
//定义导出函数参数最多为9个
func
(
m
*
StructVarDemo
)
FuncMaxParam
(
p1
,
p2
,
p3
,
p4
,
p5
,
p6
,
p7
,
p8
,
p9
string
)
{
fmt
.
Println
(
"结构类型绑定函数 FuncMaxParam 被调用 入参:"
,
p1
,
p2
,
p3
,
p4
,
p5
,
p6
,
p7
,
p8
,
p9
)
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录