Skip to content

Instantly share code, notes, and snippets.

Bruce Wang batmany13

Block or report user

Report or block batmany13

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@batmany13
batmany13 / main_test.go
Last active Aug 21, 2017
Helper methods
View main_test.go
func setupTest(t *testing.T) *require.Assertions {
assert := require.New(t)
cleanupTestCalls()
setupTestSynq()
return assert
}
func cleanupTestCalls() {
db.MustExec("TRUNCATE api_calls")
}
View main_test.go
func TestDetails(t *testing.T) {
assert := setupTest(t)
test_helper.RunSimplePost("/v1/details", "",
func(c *gin.Context) {
details(c)
},
func(r *httptest.ResponseRecorder) {
assert.Equal(400, r.Code)
resp := test_helper.ParseJson(r.Body)
assert.Equal("missing 'video_id'", resp["message"])
@batmany13
batmany13 / video.go
Created Aug 21, 2017
Value and Scan for Synq Video object
View video.go
func (v Video) Value() (driver.Value, error) {
json, err := json.Marshal(v)
return json, err
}
func (v *Video) Scan(src interface{}) error {
source, ok := src.([]byte)
if !ok {
return errors.New("Type assertion .([]byte) failed.")
}
View router.go
func setupRouter(port string) {
router := gin.Default()
v1 := router.Group("/v1")
{
v1.POST("/details", details)
v1.GET("/status", status)
}
log.Println("Running server on port :", port)
serverStarted = time.Now()
@batmany13
batmany13 / details.go
Last active Aug 29, 2017
Details Implementation via Gin
View details.go
// This will just get the video id and call the Synq api for the details
func details(c *gin.Context) {
a := ApiCall{}
c.BindJSON(&a)
if a.VideoId == "" {
c.JSON(400, gin.H{
"message": "missing 'video_id'",
})
@batmany13
batmany13 / call.go
Last active Aug 21, 2017
API Call to Synq
View call.go
func (a *ApiCall) Call() error {
defer a.Save()
start := time.Now()
video, err := sApi.GetVideo(a.VideoId)
a.Taken = time.Since(start)
if err != nil {
a.Error = err.Error()
return err
}
a.Type = "/v1/video/details"
View struct.go
type ApiCall struct {
Id int64 `db:"id" json:"id"`
Type string `db:"type" json:"type"`
CreatedAt time.Time `db:"ctime" json:"-"`
Called time.Time `db:"called" json:"called"`
VideoId string `db:"video_id" json:"video_id"`
Taken time.Duration `db:"taken" json:"taken"`
Error string `db:"error" json:"error"`
Video synq.Video `db:"result" json:"video"`
}
@batmany13
batmany13 / secrets.json
Created Aug 21, 2017
Secrets unencrypted
View secrets.json
{
"flyway": {
"password": "supersecret"
}
}
@batmany13
batmany13 / config.yml
Created Aug 21, 2017
Run coveralls only on CircleCI
View config.yml
- run:
name: Run Golang Tests
command: |
GOPATH=$GOPATH:"${SYNQ_DIR}"/"${REPO}"/vendor overalls -project=github.com/SYNQfm/"${REPO}" -covermode=atomic -debug -ignore=.git,.github,.circleci,vendor,sql,sample -- -race -v
if [ -z ${COVERALLS_TOKEN} ]; then
echo "coveralls token isn't set, skipping"
else
goveralls -coverprofile="${SYNQ_DIR}"/"${REPO}"/overalls.coverprofile -service circle-ci -repotoken "${COVERALLS_TOKEN}"
fi
@batmany13
batmany13 / config.yml
Created Aug 21, 2017
Wait for Postgres
View config.yml
- run:
name: Waiting for Postgres to be ready
command: |
for i in `seq 1 10`;
do
psql -h localhost -U $PG_USER $PG_DB -c "\t" && echo DB Up && exit 0
echo -n .
sleep 1
done
echo Failed waiting for Postgres && exit 1
You can’t perform that action at this time.