示例#1
0
func main() {

	//現在時刻の取得
	time := time.Now()

	//時刻を文字列にフォーマットして出力
	fmt.Printf("%04d/%02d/%02d %02d:%02d:%02d\n",
		time.Year(),
		time.Month(),
		time.Day(),
		time.Hour(),
		time.Minute(),
		time.Second())
}
示例#2
0
文件: client.go 项目: r7kamura/sugoi
func convertRFC3339ToSyoboiFormat(str string) (string, error) {
	time, err := time.Parse(time.RFC3339, str)
	if err != nil {
		return "", err
	}
	return fmt.Sprintf(
		"%04d%02d%02d_%02d%02d%02d",
		time.Year(),
		time.Month(),
		time.Day(),
		time.Hour(),
		time.Minute(),
		time.Second(),
	), nil
}
示例#3
0
func main() {
	fmt.Println("hello world")

	time := time.Now()
	rand.Seed(int64(time.Second()))
	port := rand.Intn(50000)
	port = port + 10000

	fmt.Println(strconv.Itoa(port), "\n")

	var jsonStr = fmt.Sprint(`{"Port":`, port, `}`)
	request, err := http.NewRequest("POST", "http://localhost:3000/machines/register_new", bytes.NewBuffer([]byte(jsonStr)))
	request.Header.Set("Content-Type", "application/json")

	client := &http.Client{}
	response, err := client.Do(request)
	if err != nil {
		fmt.Println(err)
		os.Exit(1)
	}

	defer response.Body.Close()
	body, err := ioutil.ReadAll(response.Body)
	if err != nil {
		fmt.Println(err)
		os.Exit(1)
	}
	machineId := string(body)
	fmt.Println("Registered As Machine#", machineId)

	m := martini.Classic()

	m.Get("/ping", handlePingRequest)
	//m.Post("/games/new_request", handleGameRequest)
	//m.Post("/games/:id/register_server", handleRegisterServer)

	c := make(chan os.Signal, 1)
	signal.Notify(c, os.Interrupt, syscall.SIGKILL, syscall.SIGHUP, syscall.SIGTERM, syscall.SIGINT)
	go func() {
		fmt.Println(<-c)
		shutdown(machineId)
		os.Exit(1)
	}()
	defer shutdown(machineId)

	thisIp := fmt.Sprint("localhost:", strconv.Itoa(port))
	m.RunOnAddr(thisIp)
}
示例#4
0
func printMsg(chatMsg *chatMsg) {
	if chatMsg.User == user {
		return
	}

	if chatMsg.Type == MsgTypeBroadcast {
		printSimpleMsg(chatMsg)
	} else {
		time := time.Unix(chatMsg.Time, 0)
		fmt.Printf("%s %d-%d-%d %d:%d:%d :\n", chatMsg.User, time.Year(), time.Month(), time.Day(), time.Hour(), time.Minute(), time.Second())
		fmt.Println(chatMsg.Msg)
	}
}