可以打包模板进二进制文件

pull/30/head
陶士涵 4 years ago
parent 5d46a0e455
commit 086db15aff

@ -2,6 +2,7 @@ package main
import (
"fmt"
"github.com/taoshihan1991/imaptool/tmpl"
"github.com/taoshihan1991/imaptool/tools"
"html/template"
"log"
@ -116,9 +117,8 @@ func list(w http.ResponseWriter, r *http.Request) {
render.Mails = mails
}()
t, _ := template.ParseFiles("./tmpl/index.html")
wg.Wait()
t.Execute(w, render)
tmpl.RenderList(w,render)
}
//登陆界面
@ -131,8 +131,7 @@ func login(w http.ResponseWriter, r *http.Request) {
res := tools.CheckEmailPassword(server, email, password)
if !res {
errStr = "连接或验证失败"
t, _ := template.ParseFiles("./tmpl/login.html")
t.Execute(w, errStr)
tmpl.RenderLogin(w,errStr)
} else {
auth := fmt.Sprintf("%s|%s|%s", server, email, password)
cookie := http.Cookie{
@ -143,8 +142,7 @@ func login(w http.ResponseWriter, r *http.Request) {
http.Redirect(w, r, "/", 302)
}
} else {
t, _ := template.ParseFiles("./tmpl/login.html")
t.Execute(w, nil)
tmpl.RenderLogin(w,errStr)
}
}

@ -1,3 +1,12 @@
package tmpl
import (
"html/template"
"net/http"
)
func RenderList(w http.ResponseWriter,render interface{}){
const html = `
<!doctype html>
<html lang="cn">
<head>
@ -54,4 +63,7 @@
</div>
</body>
</html>
`
t, _ := template.New("list").Parse(html)
t.Execute(w, render)
}

@ -1,3 +1,12 @@
package tmpl
import (
"html/template"
"net/http"
)
func RenderLogin(w http.ResponseWriter,render interface{}){
const html = `
<!doctype html>
<html lang="cn">
<head>
@ -87,4 +96,7 @@
</form>
</body>
</html>
`
t, _ := template.New("list").Parse(html)
t.Execute(w, render)
}
Loading…
Cancel
Save