func TestGetIndexStandard(t *testing.T) { time := time.Now().UTC() extension := fmt.Sprintf("%d.%02d.%02d", time.Year(), time.Month(), time.Day()) event := common.MapStr{ "@timestamp": common.Time(time), "field": 1, } index := getIndex(event, "beatname") assert.Equal(t, index, "beatname-"+extension) }
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) } }
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()) }
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 }
func TestGetIndexOverwrite(t *testing.T) { time := time.Now().UTC() extension := fmt.Sprintf("%d.%02d.%02d", time.Year(), time.Month(), time.Day()) event := common.MapStr{ "@timestamp": common.Time(time), "field": 1, "beat": common.MapStr{ "name": "testbeat", "index": "dynamicindex", }, } index := getIndex(event, "beatname") assert.Equal(t, index, "dynamicindex-"+extension) }
func TestGetIndexStandard(t *testing.T) { time := time.Now().UTC() extension := fmt.Sprintf("%d.%02d.%02d", time.Year(), time.Month(), time.Day()) event := common.MapStr{ "@timestamp": common.Time(time), "field": 1, } pattern := "beatname-%{+yyyy.MM.dd}" fmtstr := fmtstr.MustCompileEvent(pattern) indexSel := outil.MakeSelector(outil.FmtSelectorExpr(fmtstr, "")) index := getIndex(event, indexSel) assert.Equal(t, index, "beatname-"+extension) }
func show_db_scores(stats *Stats, well *Well, db *sql.DB, timenow int64) { well_depth := len(well.debris_map) well_width := len(well.debris_map[0]) extended_set := 0 if stats.piece_set["extd"] == true { extended_set = 1 } get_scores_sql := fmt.Sprintf(` select score, timestamp, user from stats where width = %d and depth = %d and extended_set = %d order by score desc `, well_width, well_depth, extended_set) scores, err := db.Query(get_scores_sql) if err != nil { fmt.Println("ERROR querying db\n") os.Exit(1) } defer scores.Close() var show_scores [][]string max_score_len := len("score") max_player_len := len("player") fmt.Print("\nHigh Scores:\n score - player - date\n") for scores.Next() { var score int var timestamp int64 var player string scores.Scan(&score, ×tamp, &player) score_len := len(fmt.Sprintf("%d", score)) if score_len > max_score_len { max_score_len = score_len } player_len := len(player) if player_len > max_player_len { max_player_len = player_len } asterisk := " " if timestamp == timenow { asterisk = " *" } time := time.Unix(int64(timestamp), 0) var show_score []string show_score = append(show_score, fmt.Sprintf("%d", score)) show_score = append(show_score, player) show_score = append(show_score, fmt.Sprintf("%04d-%02d-%02d", time.Year(), time.Month(), time.Day())) show_score = append(show_score, asterisk) show_scores = append(show_scores, show_score) } scores.Close() for this_score := range show_scores { format := fmt.Sprintf("%%s %%%ds - %%%ds - %%s\n", max_score_len, max_player_len) fmt.Printf(format, show_scores[this_score][3], show_scores[this_score][0], show_scores[this_score][1], show_scores[this_score][2]) } }