コード例 #1
0
ファイル: usage.go プロジェクト: riseofthetigers/microcosm
// Send usage data using ElasticSearch's bulk load UDP API
func (m *Usage) Send() {
	conn, err := net.Dial("udp", elasticSearchConnString)
	if err != nil {
		glog.Warningf("Couldn't dial: %s", err.Error())
	}
	defer conn.Close()

	coord, err := json.Marshal(map[string]interface{}{
		"index": map[string]string{
			"_index": "microcosm",
			"_type":  "log",
			"_id":    uuid.NewRandom().String(),
		},
	})
	if err != nil {
		glog.Warningf("Failed to marshal log coord: %s", err.Error())
	}
	usage, err := json.Marshal(m)
	if err != nil {
		glog.Warningf("Failed to marshal usage: %s", err.Error())
	}

	payload := fmt.Sprintf("%s\n%s\n", string(coord), string(usage))

	_, err = conn.Write([]byte(payload))
	if err != nil {
		glog.Warningf("Couldn't write usage to conn: %s", err.Error())
	}
}
コード例 #2
0
ファイル: user.go プロジェクト: wyattjoh/spacegophers
// NewUser creates a new user with a new Gopher to manage the user's new ws
// connection.
func NewUser(ctx log.Interface, ws *websocket.Conn) User {
	id := uuid.NewRandom().String()[:3]

	return User{
		ID:     id,
		Gopher: NewGopher(id, RandomCoordinates(boardSize)),
		Log:    ctx.WithField("module", "User"),
		send:   make(chan []byte, 256),
		ws:     ws,
	}
}
コード例 #3
0
ファイル: shot.go プロジェクト: iamkether/spacegophers
// NewShot returns a new shot from a given Gopher. The location is set to the
// middle of the gopher and is fired at the speed of the gopher plus the shot's
// own speed in the direction of the angle of the Gopher.
func NewShot(u *User, g Gopher) Shot {
	posx := g.Position.X + math.Cos(g.Angle)*halfGopherSize
	posy := g.Position.Y + math.Sin(g.Angle)*halfGopherSize

	velx := g.Velocity.X + math.Cos(g.Angle)*shotSpeed
	vely := g.Velocity.Y + math.Sin(g.Angle)*shotSpeed

	return Shot{
		ID:         uuid.NewRandom().String(),
		Gopher:     g.UserID,
		User:       u,
		Entity:     NewEntity(thrustAcceleration, posx, posy, velx, vely, g.Angle),
		Lifecycles: int64(defaultLifeCycles),
	}
}
コード例 #4
0
ファイル: analytics.go プロジェクト: wyattjoh/analytics-go
// Return uuid string.
func uid() string {
	return uuid.NewRandom().String()
}
コード例 #5
0
ファイル: game.go プロジェクト: wyattjoh/spacegophers
// NewGameID creates a new game id to be used.
func NewGameID() string {
	return uuid.NewRandom().String()[0:8]
}