Skip to content

Instantly share code, notes, and snippets.

package main
import (
"context"
"io/ioutil"
"log"
"net/http"
"os"
"os/signal"
"syscall"
@timakin
timakin / golden.go
Created September 28, 2019 05:06
Testutil for e2e test in Go API
package testutils
import (
"encoding/json"
"fmt"
"io/ioutil"
"path"
"path/filepath"
"runtime"
"testing"
@timakin
timakin / time.go
Created September 28, 2019 05:02
Test Utility for time package
package library
import "time"
var fakeTime time.Time
func SetFakeTime(t time.Time) {
fakeTime = t
}
func DatastoreWithContext(ctx context.Context) context.Context {
ds, err := aedatastore.FromContext(ctx)
if err != nil {
panic(err)
}
ds.AppendMiddleware(localcache.New(
localcache.WithLogger(func(ctx context.Context, format string, args ...interface{}) {
fmt.Println(fmt.Sprintf(format, args...))
}),
func (repo videoRepository) getVideosByPublishedAt(ctx context.Context, so *entity.SearchOptions) ([]*entity.Video, string, error) {
g, err := infrastructure.BoomFromContext(ctx)
if err != nil {
return nil, "", err
}
query := g.Client.NewQuery("Video").Filter("Enabled = ", true).Limit(so.Paging.Limit).Order("-PublishedAt").KeysOnly()
if so.Paging.Cursor != "" {
cursor, err := g.DecodeCursor(so.Paging.Cursor)
if err != nil {
return nil, "", err
@timakin
timakin / gist:536e632cce1a6310d64bc0d3fe89d91c
Created December 2, 2018 06:19
getVideosByPublishedAt
func (repo videoRepository) getVideosByPublishedAt(ctx context.Context, so *entity.SearchOptions) ([]*entity.Video, string, error) {
var vs []*entity.Video
g, err := infrastructure.BoomFromContext(ctx)
if err != nil {
return nil, "", err
}
query := g.Client.NewQuery("Video").Filter("Enabled = ", true).Limit(so.Paging.Limit).Order("-PublishedAt")
if so.Paging.Cursor != "" {
cursor, err := g.DecodeCursor(so.Paging.Cursor)
if err != nil {
package main
import (
"bytes"
"os"
"time"
vegeta "github.com/tsenart/vegeta/lib"
)
@timakin
timakin / sub.go
Last active May 29, 2018 06:05
Live status subscription
// StartStatusSubscription ... ライブ動画の放送状況の監視
func (s *liveProgramService) StartStatusSubscription(ctx context.Context) {
s.subLock.Do(func() {
sub, err := s.sub.GetSubscriber()
if err != nil {
panic(err)
}
go func(sub *redis.PubSub) {
defer sub.Close()
for {
@timakin
timakin / convert.sh
Last active November 15, 2017 15:07
files="./*.mp4"
for filepath in $files; do
fname_ext="${filepath##*/}"
fname="${fname_ext%.*}"
echo $fname
ffmpeg -i "${fname}.mp4" -vcodec h264 -acodec aac "${fname}_comp.mp4"
done
@timakin
timakin / langToMap.go
Created October 26, 2017 13:07
langToMap.go
package main
import (
"fmt"
)
type Language struct {
ID int
Code string
}