mirror of
https://gitee.com/johng/gf
synced 2026-06-06 16:21:40 +08:00
gofmt geg/third
This commit is contained in:
@ -8,7 +8,7 @@ import (
|
||||
)
|
||||
|
||||
func main() {
|
||||
array := g.Slice{2, 3, 1, 5, 4, 6, 8, 7, 9}
|
||||
array := g.Slice{2, 3, 1, 5, 4, 6, 8, 7, 9}
|
||||
hashMap := gmap.New(true)
|
||||
linkMap := gmap.NewLinkMap(true)
|
||||
treeMap := gmap.NewTreeMap(gutil.ComparatorInt, true)
|
||||
|
||||
@ -28,5 +28,5 @@ func main() {
|
||||
// 丢回池中以便重复使用
|
||||
p.Put(conn)
|
||||
// 等待一定时间观察过期方法调用
|
||||
time.Sleep(4*time.Second)
|
||||
time.Sleep(4 * time.Second)
|
||||
}
|
||||
|
||||
@ -18,12 +18,12 @@ func main() {
|
||||
// 消费者,不停读取队列数据并输出到终端
|
||||
for {
|
||||
select {
|
||||
case v := <-queue.C:
|
||||
if v != nil {
|
||||
fmt.Println(v)
|
||||
} else {
|
||||
return
|
||||
}
|
||||
case v := <-queue.C:
|
||||
if v != nil {
|
||||
fmt.Println(v)
|
||||
} else {
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -25,4 +25,4 @@ func main() {
|
||||
fmt.Println(key, value)
|
||||
return true
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@ -18,4 +18,4 @@ func main() {
|
||||
fmt.Println(key, value)
|
||||
return true
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@ -14,4 +14,4 @@ func main() {
|
||||
tree.Print()
|
||||
tree.Flip()
|
||||
tree.Print()
|
||||
}
|
||||
}
|
||||
|
||||
@ -12,10 +12,10 @@ func main() {
|
||||
db.SetDebug(true)
|
||||
|
||||
r, e := db.Table("user").Data(g.Map{
|
||||
"passport" : "1",
|
||||
"password" : "1",
|
||||
"nickname" : "1",
|
||||
"create_time" : time.Now(),
|
||||
"passport": "1",
|
||||
"password": "1",
|
||||
"nickname": "1",
|
||||
"create_time": time.Now(),
|
||||
}).Insert()
|
||||
if e != nil {
|
||||
panic(e)
|
||||
|
||||
@ -1,8 +1,8 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/gogf/gf/g"
|
||||
"fmt"
|
||||
"github.com/gogf/gf/g"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
||||
@ -6,7 +6,7 @@ import (
|
||||
)
|
||||
|
||||
func main() {
|
||||
src := "~{;(<dR;:x>F#,6@WCN^O`GW!#"
|
||||
src := "~{;(<dR;:x>F#,6@WCN^O`GW!#"
|
||||
srcCharset := "GB2312"
|
||||
dstCharset := "UTF-8"
|
||||
str, err := gcharset.Convert(dstCharset, srcCharset, src)
|
||||
|
||||
@ -10,7 +10,7 @@ import (
|
||||
func main() {
|
||||
c := ghttp.NewClient()
|
||||
c.Transport = &http.Transport{
|
||||
TLSClientConfig : &tls.Config{ InsecureSkipVerify: true},
|
||||
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
|
||||
}
|
||||
r, e := c.Clone().Get("https://127.0.0.1:8199")
|
||||
fmt.Println(e)
|
||||
|
||||
@ -7,7 +7,6 @@ import (
|
||||
"github.com/gogf/gf/g/os/glog"
|
||||
)
|
||||
|
||||
|
||||
func ws(r *ghttp.Request) {
|
||||
ws, err := r.WebSocket()
|
||||
if err != nil {
|
||||
|
||||
@ -8,14 +8,14 @@ import (
|
||||
)
|
||||
|
||||
// 自定义格式发送消息包
|
||||
func SendPkg(conn *gtcp.Conn, act string, data...string) error {
|
||||
func SendPkg(conn *gtcp.Conn, act string, data ...string) error {
|
||||
s := ""
|
||||
if len(data) > 0 {
|
||||
s = data[0]
|
||||
}
|
||||
msg, err := json.Marshal(types.Msg{
|
||||
Act : act,
|
||||
Data : s,
|
||||
Act: act,
|
||||
Data: s,
|
||||
})
|
||||
if err != nil {
|
||||
panic(err)
|
||||
@ -35,4 +35,4 @@ func RecvPkg(conn *gtcp.Conn) (msg *types.Msg, err error) {
|
||||
}
|
||||
return msg, err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -36,12 +36,15 @@ func main() {
|
||||
break
|
||||
}
|
||||
switch msg.Act {
|
||||
case "hello": onServerHello(conn, msg)
|
||||
case "doexit": onServerDoExit(conn, msg)
|
||||
case "heartbeat": onServerHeartBeat(conn, msg)
|
||||
default:
|
||||
glog.Errorf("invalid message: %v", msg)
|
||||
break
|
||||
case "hello":
|
||||
onServerHello(conn, msg)
|
||||
case "doexit":
|
||||
onServerDoExit(conn, msg)
|
||||
case "heartbeat":
|
||||
onServerHeartBeat(conn, msg)
|
||||
default:
|
||||
glog.Errorf("invalid message: %v", msg)
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -57,4 +60,4 @@ func onServerHeartBeat(conn *gtcp.Conn, msg *types.Msg) {
|
||||
func onServerDoExit(conn *gtcp.Conn, msg *types.Msg) {
|
||||
glog.Printf("exit command from [%s]", conn.RemoteAddr().String())
|
||||
conn.Close()
|
||||
}
|
||||
}
|
||||
|
||||
@ -25,11 +25,13 @@ func main() {
|
||||
break
|
||||
}
|
||||
switch msg.Act {
|
||||
case "hello": onClientHello(conn, msg)
|
||||
case "heartbeat": onClientHeartBeat(conn, msg)
|
||||
default:
|
||||
glog.Errorfln("invalid message: %v", msg)
|
||||
break
|
||||
case "hello":
|
||||
onClientHello(conn, msg)
|
||||
case "heartbeat":
|
||||
onClientHeartBeat(conn, msg)
|
||||
default:
|
||||
glog.Errorfln("invalid message: %v", msg)
|
||||
break
|
||||
}
|
||||
}
|
||||
}).Run()
|
||||
|
||||
@ -34,6 +34,6 @@ func main() {
|
||||
if err := conn.SendPkg([]byte(gconv.String(i))); err != nil {
|
||||
glog.Error(err.Error())
|
||||
}
|
||||
time.Sleep(1*time.Second)
|
||||
time.Sleep(1 * time.Second)
|
||||
}
|
||||
}
|
||||
|
||||
@ -33,6 +33,6 @@ func main() {
|
||||
if err := conn.SendPkg(nil); err != nil {
|
||||
glog.Error(err)
|
||||
}
|
||||
time.Sleep(1*time.Second)
|
||||
time.Sleep(1 * time.Second)
|
||||
}
|
||||
}
|
||||
|
||||
@ -13,7 +13,7 @@ func main() {
|
||||
go gtcp.NewServer("127.0.0.1:8999", func(conn *gtcp.Conn) {
|
||||
defer conn.Close()
|
||||
for {
|
||||
data, err := conn.RecvPkg(gtcp.PkgOption{MaxSize : 1})
|
||||
data, err := conn.RecvPkg(gtcp.PkgOption{MaxSize: 1})
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
break
|
||||
@ -34,6 +34,6 @@ func main() {
|
||||
if err := conn.SendPkg([]byte(gconv.String(i))); err != nil {
|
||||
glog.Error(err)
|
||||
}
|
||||
time.Sleep(1*time.Second)
|
||||
time.Sleep(1 * time.Second)
|
||||
}
|
||||
}
|
||||
|
||||
@ -18,15 +18,15 @@ func main() {
|
||||
defer conn.Close()
|
||||
// 使用JSON格式化数据字段
|
||||
info, err := json.Marshal(types.NodeInfo{
|
||||
Cpu : float32(66.66),
|
||||
Host : "localhost",
|
||||
Ip : g.Map {
|
||||
"etho" : "192.168.1.100",
|
||||
"eth1" : "114.114.10.11",
|
||||
Cpu: float32(66.66),
|
||||
Host: "localhost",
|
||||
Ip: g.Map{
|
||||
"etho": "192.168.1.100",
|
||||
"eth1": "114.114.10.11",
|
||||
},
|
||||
MemUsed : 15560320,
|
||||
MemTotal : 16333788,
|
||||
Time : int(gtime.Second()),
|
||||
MemUsed: 15560320,
|
||||
MemTotal: 16333788,
|
||||
Time: int(gtime.Second()),
|
||||
})
|
||||
if err != nil {
|
||||
panic(err)
|
||||
|
||||
@ -3,10 +3,10 @@ package types
|
||||
import "github.com/gogf/gf/g"
|
||||
|
||||
type NodeInfo struct {
|
||||
Cpu float32 // CPU百分比(%)
|
||||
Host string // 主机名称
|
||||
Ip g.Map // IP地址信息(可能多个)
|
||||
MemUsed int // 内存使用(byte)
|
||||
MemTotal int // 内存总量(byte)
|
||||
Time int // 上报时间(时间戳)
|
||||
Cpu float32 // CPU百分比(%)
|
||||
Host string // 主机名称
|
||||
Ip g.Map // IP地址信息(可能多个)
|
||||
MemUsed int // 内存使用(byte)
|
||||
MemTotal int // 内存总量(byte)
|
||||
Time int // 上报时间(时间戳)
|
||||
}
|
||||
|
||||
@ -6,7 +6,6 @@ import (
|
||||
"time"
|
||||
)
|
||||
|
||||
|
||||
func main() {
|
||||
gcron.SetLogLevel(glog.LEVEL_ALL)
|
||||
gcron.Add("* * * * * ?", func() {
|
||||
|
||||
@ -6,10 +6,10 @@ import (
|
||||
|
||||
func main() {
|
||||
l := glog.New()
|
||||
l.SetFlags(glog.F_TIME_TIME|glog.F_FILE_SHORT)
|
||||
l.SetFlags(glog.F_TIME_TIME | glog.F_FILE_SHORT)
|
||||
l.Println("time and short line number")
|
||||
l.SetFlags(glog.F_TIME_MILLI|glog.F_FILE_LONG)
|
||||
l.SetFlags(glog.F_TIME_MILLI | glog.F_FILE_LONG)
|
||||
l.Println("time with millisecond and long line number")
|
||||
l.SetFlags(glog.F_TIME_STD|glog.F_FILE_LONG)
|
||||
l.SetFlags(glog.F_TIME_STD | glog.F_FILE_LONG)
|
||||
l.Println("standard time format and long line number")
|
||||
}
|
||||
|
||||
@ -6,7 +6,7 @@ import (
|
||||
)
|
||||
|
||||
func main() {
|
||||
glog.Debug(g.Map{"uid" : 100, "name" : "john"})
|
||||
glog.Debug(g.Map{"uid": 100, "name": "john"})
|
||||
|
||||
type User struct {
|
||||
Uid int `json:"uid"`
|
||||
|
||||
@ -7,7 +7,7 @@ import (
|
||||
|
||||
func main() {
|
||||
wg := sync.WaitGroup{}
|
||||
c := make(chan struct{})
|
||||
c := make(chan struct{})
|
||||
wg.Add(3000)
|
||||
for i := 0; i < 3000; i++ {
|
||||
go func() {
|
||||
|
||||
@ -22,7 +22,7 @@ func (w *MyWriter) Write(p []byte) (n int, err error) {
|
||||
|
||||
func main() {
|
||||
glog.SetWriter(&MyWriter{
|
||||
logger : glog.New(),
|
||||
logger: glog.New(),
|
||||
})
|
||||
glog.Fatal("FATAL ERROR")
|
||||
}
|
||||
|
||||
@ -7,7 +7,7 @@ import (
|
||||
)
|
||||
|
||||
func main() {
|
||||
p := grpool.New(1)
|
||||
p := grpool.New(1)
|
||||
wg := sync.WaitGroup{}
|
||||
for i := 0; i < 10; i++ {
|
||||
wg.Add(1)
|
||||
|
||||
@ -12,7 +12,7 @@ func main() {
|
||||
v := i
|
||||
p.Add(func() {
|
||||
fmt.Println(v)
|
||||
time.Sleep(3*time.Second)
|
||||
time.Sleep(3 * time.Second)
|
||||
})
|
||||
}
|
||||
time.Sleep(time.Minute)
|
||||
|
||||
@ -13,5 +13,5 @@ func main() {
|
||||
})
|
||||
}
|
||||
fmt.Println("start")
|
||||
time.Sleep(48*time.Hour)
|
||||
time.Sleep(48 * time.Hour)
|
||||
}
|
||||
|
||||
@ -13,7 +13,7 @@ func funcTest() string {
|
||||
|
||||
func main() {
|
||||
// 解析模板的时候传递模板函数映射Map,仅会在当前模板解析生效
|
||||
parsed, err := g.View().ParseContent(`call build-in function test: {{test}}`, nil, gview.FuncMap {
|
||||
parsed, err := g.View().ParseContent(`call build-in function test: {{test}}`, nil, gview.FuncMap{
|
||||
"test": funcTest,
|
||||
})
|
||||
if err != nil {
|
||||
|
||||
@ -28,4 +28,3 @@ func main() {
|
||||
}
|
||||
fmt.Println(string(parsed2))
|
||||
}
|
||||
|
||||
|
||||
@ -5,7 +5,6 @@ import (
|
||||
"github.com/gogf/gf/g/frame/gmvc"
|
||||
)
|
||||
|
||||
|
||||
type Controller struct {
|
||||
gmvc.Controller
|
||||
}
|
||||
|
||||
@ -9,4 +9,4 @@ func main() {
|
||||
e, err := ianaindex.MIB.Encoding("GB2312")
|
||||
fmt.Println(err)
|
||||
fmt.Println(e)
|
||||
}
|
||||
}
|
||||
|
||||
@ -7,8 +7,8 @@ import (
|
||||
|
||||
func main() {
|
||||
type Ids struct {
|
||||
Id int `json:"id"`
|
||||
Uid int `json:"uid"`
|
||||
Id int `json:"id"`
|
||||
Uid int `json:"uid"`
|
||||
}
|
||||
type Base struct {
|
||||
Ids
|
||||
@ -16,16 +16,16 @@ func main() {
|
||||
}
|
||||
type User struct {
|
||||
Base
|
||||
Passport string `json:"passport"`
|
||||
Password string `json:"password"`
|
||||
Nickname string `json:"nickname"`
|
||||
Passport string `json:"passport"`
|
||||
Password string `json:"password"`
|
||||
Nickname string `json:"nickname"`
|
||||
}
|
||||
user := new(User)
|
||||
user.Id = 1
|
||||
user.Uid = 100
|
||||
user.Nickname = "John"
|
||||
user.Passport = "johng"
|
||||
user.Password = "123456"
|
||||
user.Id = 1
|
||||
user.Uid = 100
|
||||
user.Nickname = "John"
|
||||
user.Passport = "johng"
|
||||
user.Password = "123456"
|
||||
user.CreateTime = "2019"
|
||||
g.Dump(gconv.MapDeep(user))
|
||||
}
|
||||
|
||||
@ -7,8 +7,8 @@ import (
|
||||
|
||||
func main() {
|
||||
type Ids struct {
|
||||
Id int `json:"id"`
|
||||
Uid int `json:"uid"`
|
||||
Id int `json:"id"`
|
||||
Uid int `json:"uid"`
|
||||
}
|
||||
type Base struct {
|
||||
Ids
|
||||
@ -16,17 +16,17 @@ func main() {
|
||||
}
|
||||
type User struct {
|
||||
Base
|
||||
Passport string `json:"passport"`
|
||||
Password string `json:"password"`
|
||||
Nickname string `json:"nickname"`
|
||||
Passport string `json:"passport"`
|
||||
Password string `json:"password"`
|
||||
Nickname string `json:"nickname"`
|
||||
}
|
||||
data := g.Map{
|
||||
"id" : 1,
|
||||
"uid" : 100,
|
||||
"passport" : "johng",
|
||||
"password" : "123456",
|
||||
"nickname" : "John",
|
||||
"create_time" : "2019",
|
||||
"id": 1,
|
||||
"uid": 100,
|
||||
"passport": "johng",
|
||||
"password": "123456",
|
||||
"nickname": "John",
|
||||
"create_time": "2019",
|
||||
}
|
||||
user := new(User)
|
||||
gconv.StructDeep(data, user)
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@ -720,7 +720,7 @@ var appendTestsNFC = []AppendTest{
|
||||
}
|
||||
|
||||
var appendTestsNFD = []AppendTest{
|
||||
// TODO: Move some of the tests here.
|
||||
// TODO: Move some of the tests here.
|
||||
}
|
||||
|
||||
var appendTestsNFKC = []AppendTest{
|
||||
|
||||
Reference in New Issue
Block a user