-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsv.go
76 lines (65 loc) · 1.24 KB
/
sv.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package rpcsv
import (
"github.com/toukii/goutils"
"net"
"net/rpc"
// "bytes"
// "fmt"
"html/template"
)
func NewBufWriter() *BufWriter {
return &BufWriter{
buf: make([]byte, 1000, 1024),
}
}
type BufWriter struct {
buf []byte
}
func (w *BufWriter) Write(p []byte) (n int, err error) {
w.buf = p
return len(w.buf), nil
}
func (w *BufWriter) Bytes() []byte {
return w.buf
}
func RPCServe(port string) (net.Listener, error) {
_rpc := new(RPC)
server := rpc.NewServer()
server.Register(_rpc)
lis, err := net.Listen("tcp", ":"+port)
if goutils.CheckErr(err) {
return nil, err
}
go server.Accept(lis)
return lis, nil
}
var (
Theme *template.Template
theme_bs []byte
)
func init() {
theme_bs = goutils.ReadFile("theme.thm")
if nil == theme_bs {
theme_bs = goutils.ToByte(theme_s)
}
var err error
Theme, err = template.New("theme.thm").Parse(goutils.ToString(theme_bs))
if err != nil {
panic("theme error")
}
}
func UpdataTheme() bool {
theme_bs = goutils.ReadFile("theme.thm")
if nil == theme_bs {
theme_bs = goutils.ToByte(theme_s)
}
var err error
Theme, err = template.New("theme.thm").Parse(goutils.ToString(theme_bs))
if err != nil {
panic("theme error")
}
return true
}
const (
theme_s = `{{.MDContent}}`
)