<html>
<head>
<title>卧槽</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<style>
.div>label{
width: 100px;
display: inherit;
}
.div>input{
height: 30px;
}
</style>
<body>
<div class="div">
<label for="">MD5加密</label>
<input type="text" style="width: 250px; margin: 0 auto;" id="input1" >
<input type="button" style="width: 125px; margin: 0 auto;" value="转换" id="button1">
<input type="text" style="width: 250px; margin: 0 auto;" id="output1" >
</div>
<div class="div">
<label for="">base64</label>
<input type="text" style="width: 250px; margin: 0 auto;" id="input2" >
<input type="button" style="width: 125px; margin: 0 auto;" value="转换" id="button2">
<input type="text" style="width: 250px; margin: 0 auto;" id="output2" >
</div>
</body>
</html>
package main
import (
"crypto/md5"
"encoding/base64"
"fmt"
"github.com/fatih/color"
"github.com/sciter-sdk/go-sciter"
"github.com/sciter-sdk/go-sciter/window"
"io"
)
var root2 *sciter.Element
var rootSelectorErr2 error
var w2 *window.Window
var windowErr2 error
func init() {
rect := sciter.NewRect(0, 100, 300, 350)
w2, windowErr2 = window.New(sciter.SW_TITLEBAR|
sciter.SW_CONTROLS|
sciter.SW_MAIN|
sciter.SW_GLASSY,
rect)
if windowErr2 != nil {
fmt.Println("Can not create new window")
return
}
htloadErr := w2.LoadFile("D:/go/src/gui/demo3.html")
if htloadErr != nil {
fmt.Println("Can not load html in the screen", htloadErr.Error())
return
}
root2, rootSelectorErr2 = w2.GetRootElement()
if rootSelectorErr2 != nil {
fmt.Println("Can not select root element")
return
}
w2.SetTitle("卧槽")
}
func main() {
addbutton1, _ := root2.SelectById("button1")
output1, errout1 := root2.SelectById("output1")
if errout1 != nil {
color.Red("failed to bound output 1 ", errout1.Error())
}
addbutton1.OnClick(func() {
output := button1()
output1.SetText(fmt.Sprint(output))
})
addbutton2, _ := root2.SelectById("button2")
output2, errout2 := root2.SelectById("output2")
if errout2 != nil {
color.Red("failed to bound output 1 ", errout2.Error())
}
addbutton2.OnClick(func() {
result2 := button2()
output2.SetText(fmt.Sprint(result2))
})
w2.Show()
w2.Run()
}
func button1() string {
string1, errin1 := root2.SelectById("input1")
if errin1 != nil {
color.Red("failed to bound input 1 ", errin1.Error())
}
string1val, errv1 := string1.GetValue()
color.Green(string1val.String())
if errv1 != nil {
color.Red(errv1.Error())
}
w2 := md5.New()
io.WriteString(w2, string1val.String())
md5str2 := fmt.Sprintf("%x", w2.Sum(nil))
return md5str2
}
func button2() string {
string2, errin2 := root2.SelectById("input2")
if errin2 != nil {
color.Red("failed to bound input 1 ", errin2.Error())
}
string2val, errv2 := string2.GetValue()
color.Green(string2val.String())
if errv2 != nil {
color.Red(errv2.Error())
}
return base64.StdEncoding.EncodeToString([]byte(string2val.String()))
}