mirror of
https://gitee.com/johng/gf
synced 2026-06-27 01:43:33 +08:00
示例更新
This commit is contained in:
@ -1,4 +1,5 @@
|
||||
// from https://github.com/google/btree
|
||||
|
||||
package gbtree
|
||||
|
||||
import (
|
||||
|
||||
@ -3,6 +3,7 @@
|
||||
// This Source Code Form is subject to the terms of the MIT License.
|
||||
// If a copy of the MIT was not distributed with this file,
|
||||
// You can obtain one at https://gitee.com/johng/gf.
|
||||
|
||||
package ghttp
|
||||
|
||||
import (
|
||||
|
||||
18
geg/net/ghttp/domain.go
Normal file
18
geg/net/ghttp/domain.go
Normal file
@ -0,0 +1,18 @@
|
||||
package main
|
||||
|
||||
import "gitee.com/johng/gf/g/net/ghttp"
|
||||
|
||||
func Hello1(s *ghttp.Server, r *ghttp.ClientRequest, w *ghttp.ServerResponse) {
|
||||
w.WriteString("Hello World1!")
|
||||
}
|
||||
|
||||
func Hello2(s *ghttp.Server, r *ghttp.ClientRequest, w *ghttp.ServerResponse) {
|
||||
w.WriteString("Hello World2!")
|
||||
}
|
||||
|
||||
func main() {
|
||||
s := ghttp.GetServer()
|
||||
s.Domain("127.0.0.1").BindHandler("/", Hello1)
|
||||
s.Domain("localhost").BindHandler("/", Hello2)
|
||||
s.Run()
|
||||
}
|
||||
13
geg/net/ghttp/ghttp_server.go
Normal file
13
geg/net/ghttp/ghttp_server.go
Normal file
@ -0,0 +1,13 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"gitee.com/johng/gf/g/net/ghttp"
|
||||
)
|
||||
|
||||
func main() {
|
||||
s := ghttp.GetServer()
|
||||
s.SetAddr(":8199")
|
||||
s.SetIndexFolder(true)
|
||||
s.SetServerRoot("/tmp")
|
||||
s.Run()
|
||||
}
|
||||
21
geg/net/ghttp/ghttp_server2.go
Normal file
21
geg/net/ghttp/ghttp_server2.go
Normal file
@ -0,0 +1,21 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"gitee.com/johng/gf/g/net/ghttp"
|
||||
)
|
||||
|
||||
func main() {
|
||||
s1 := ghttp.GetServer("s1")
|
||||
s1.SetAddr(":8198")
|
||||
s1.SetIndexFolder(true)
|
||||
s1.SetServerRoot("/home/www/static1")
|
||||
go s1.Run()
|
||||
|
||||
s2 := ghttp.GetServer("s2")
|
||||
s2.SetAddr(":8199")
|
||||
s2.SetIndexFolder(true)
|
||||
s2.SetServerRoot("/home/www/static2")
|
||||
go s2.Run()
|
||||
|
||||
select{}
|
||||
}
|
||||
12
geg/net/ghttp/hello_world.go
Normal file
12
geg/net/ghttp/hello_world.go
Normal file
@ -0,0 +1,12 @@
|
||||
package main
|
||||
|
||||
import "gitee.com/johng/gf/g/net/ghttp"
|
||||
|
||||
func Hello(s *ghttp.Server, r *ghttp.ClientRequest, w *ghttp.ServerResponse) {
|
||||
w.WriteString("Hello World!")
|
||||
}
|
||||
func main() {
|
||||
s := ghttp.GetServer()
|
||||
s.BindHandler("/", Hello)
|
||||
s.Run()
|
||||
}
|
||||
@ -1,29 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"io"
|
||||
"gitee.com/johng/gf/g/net/ghttp"
|
||||
)
|
||||
|
||||
func HelloServer1(w http.ResponseWriter, r *http.Request) {
|
||||
io.WriteString(w, "hello1!\n")
|
||||
}
|
||||
func HelloServer2(w http.ResponseWriter, r *http.Request) {
|
||||
io.WriteString(w, "hello2\n")
|
||||
}
|
||||
func main() {
|
||||
s := ghttp.GetServer()
|
||||
s.SetAddr(":8199")
|
||||
s.SetIndexFolder(true)
|
||||
s.SetServerRoot("/home/john/Workspace/")
|
||||
s.BindHandleByMap(ghttp.HandlerMap {
|
||||
"/h": HelloServer1,
|
||||
"/h1": HelloServer1,
|
||||
"/h2": HelloServer1,
|
||||
"/h3": HelloServer1,
|
||||
})
|
||||
s.BindHandle("/hello1", HelloServer1)
|
||||
s.BindHandle("/hello2", HelloServer2)
|
||||
s.Run()
|
||||
}
|
||||
@ -1,25 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"gitee.com/johng/gf/g/net/graft"
|
||||
"gitee.com/johng/gf/g/net/gip"
|
||||
"log"
|
||||
)
|
||||
|
||||
|
||||
|
||||
func main() {
|
||||
ips, err := gipv4.IntranetIP()
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
for _, ip := range ips {
|
||||
//fmt.Println(ip)
|
||||
graft.NewServerByIp(ip).Run()
|
||||
}
|
||||
select {
|
||||
|
||||
}
|
||||
}
|
||||
@ -1,29 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"net"
|
||||
"log"
|
||||
"gitee.com/johng/gf/g/net/graft"
|
||||
"fmt"
|
||||
"gitee.com/johng/gf/g/encoding/gjson"
|
||||
)
|
||||
|
||||
func rpcLogSet() {
|
||||
conn, err := net.Dial("tcp", "192.168.2.124:4167")
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
return
|
||||
}
|
||||
|
||||
entry := graft.LogRequest{}
|
||||
entry.Key = "name3"
|
||||
entry.Value = "john3"
|
||||
fmt.Println(*gjson.Encode(entry))
|
||||
e := graft.SendMsg(conn, 100, *gjson.Encode(entry))
|
||||
fmt.Println(e)
|
||||
conn.Close()
|
||||
}
|
||||
|
||||
func main() {
|
||||
rpcLogSet()
|
||||
}
|
||||
Reference in New Issue
Block a user