parent
c2dfd09e9f
commit
f0a7b23efb
@ -1,101 +0,0 @@ |
||||
package main |
||||
|
||||
import ( |
||||
"errors" |
||||
"fmt" |
||||
log "github.com/sirupsen/logrus" |
||||
"github.com/sneak/poker" |
||||
"io" |
||||
"net/http" |
||||
"net/rpc" |
||||
"net/rpc/jsonrpc" |
||||
"os" |
||||
"time" |
||||
) |
||||
|
||||
type JSONRPCServer struct { |
||||
*rpc.Server |
||||
} |
||||
|
||||
func NewJSONRPCServer() *JSONRPCServer { |
||||
return &JSONRPCServer{rpc.NewServer()} |
||||
} |
||||
|
||||
func (s *JSONRPCServer) ServeHTTP(w http.ResponseWriter, req *http.Request) { |
||||
log.Println("rpc server got a request") |
||||
conn, _, err := w.(http.Hijacker).Hijack() |
||||
if err != nil { |
||||
log.Print("rpc hijacking ", req.RemoteAddr, ": ", err.Error()) |
||||
return |
||||
} |
||||
io.WriteString(conn, "HTTP/1.0 200 Connected to Go JSON-RPC\n\n") |
||||
codec := jsonrpc.NewServerCodec(conn) |
||||
log.Println("ServeCodec") |
||||
s.Server.ServeCodec(codec) |
||||
log.Println("finished serving request") |
||||
} |
||||
|
||||
type Args struct { |
||||
A, B int |
||||
} |
||||
|
||||
type Quotient struct { |
||||
Quo, Rem int |
||||
} |
||||
|
||||
type Arith int |
||||
|
||||
func (t *Arith) Multiply(args *Args, reply *int) error { |
||||
*reply = args.A * args.B |
||||
return nil |
||||
} |
||||
|
||||
func (t *Arith) Divide(args *Args, quo *Quotient) error { |
||||
if args.B == 0 { |
||||
return errors.New("divide by zero") |
||||
} |
||||
quo.Quo = args.A / args.B |
||||
quo.Rem = args.A % args.B |
||||
return nil |
||||
} |
||||
|
||||
func main() { |
||||
//log.SetFormatter(&log.JSONFormatter{})
|
||||
|
||||
// Output to stdout instead of the default stderr
|
||||
// Can be any io.Writer, see below for File example
|
||||
log.SetOutput(os.Stdout) |
||||
|
||||
// Only log the warning severity or above.
|
||||
//log.SetLevel(log.WarnLevel)
|
||||
|
||||
log.Infof("starting up") |
||||
|
||||
go runHttpServer() |
||||
|
||||
running := true |
||||
|
||||
for running { |
||||
time.Sleep(1 * time.Second) |
||||
} |
||||
} |
||||
|
||||
func runHttpServer() { |
||||
js := NewJSONRPCServer() |
||||
arith := new(Arith) |
||||
js.Register(arith) |
||||
|
||||
port := 8080 |
||||
|
||||
listenaddr := fmt.Sprintf("0.0.0.0:%d", port) |
||||
|
||||
s := &http.Server{ |
||||
Addr: listenaddr, |
||||
Handler: js, |
||||
ReadTimeout: 10 * time.Second, |
||||
WriteTimeout: 10 * time.Second, |
||||
MaxHeaderBytes: 1 << 20, |
||||
} |
||||
log.Infof("starting up http server %s", listenaddr) |
||||
log.Fatal(s.ListenAndServe()) |
||||
} |
@ -0,0 +1,9 @@ |
||||
module github.com/sneak/poker |
||||
|
||||
go 1.13 |
||||
|
||||
require ( |
||||
github.com/logrusorgru/aurora v0.0.0-20191116043053-66b7ad493a23 |
||||
github.com/sirupsen/logrus v1.4.2 |
||||
github.com/stretchr/testify v1.4.0 |
||||
) |
@ -0,0 +1,21 @@ |
||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= |
||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= |
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= |
||||
github.com/konsorten/go-windows-terminal-sequences v1.0.1 h1:mweAR1A6xJ3oS2pRaGiHgQ4OO8tzTaLawm8vnODuwDk= |
||||
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= |
||||
github.com/logrusorgru/aurora v0.0.0-20191116043053-66b7ad493a23 h1:Wp7NjqGKGN9te9N/rvXYRhlVcrulGdxnz8zadXWs7fc= |
||||
github.com/logrusorgru/aurora v0.0.0-20191116043053-66b7ad493a23/go.mod h1:7rIyQOR62GCctdiQpZ/zOJlFyk6y+94wXzv6RNZgaR4= |
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= |
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= |
||||
github.com/sirupsen/logrus v1.4.2 h1:SPIRibHv4MatM3XXNO2BJeFLZwZ2LvZgfQ5+UNI2im4= |
||||
github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE= |
||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= |
||||
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= |
||||
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= |
||||
github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk= |
||||
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= |
||||
golang.org/x/sys v0.0.0-20190422165155-953cdadca894 h1:Cz4ceDQGXuKRnVBDTS23GTn/pU5OE2C0WrNTOYK1Uuc= |
||||
golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= |
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= |
||||
gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw= |
||||
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= |
@ -0,0 +1,17 @@ |
||||
package poker |
||||
|
||||
//import "github.com/stretchr/testify/assert"
|
||||
import "fmt" |
||||
import "testing" |
||||
|
||||
func TestPokerHand(t *testing.T) { |
||||
|
||||
var v int64 |
||||
for { |
||||
v = int64(cryptoUint64()) |
||||
d := NewDeckFromSeed(v) |
||||
holeCards := d.Deal(2) |
||||
commCards := d.Deal(5) |
||||
fmt.Printf("%s %s\n", holeCards, commCards) |
||||
} |
||||
} |
Loading…
Reference in new issue