Skip to content

Instantly share code, notes, and snippets.

assert.Equal(t, got, tt.want, "they should be equal")
@plutov
plutov / stack.go
Created August 21, 2018 02:36
stack
package main
import (
"fmt"
)
type Node struct {
Value int
}
@plutov
plutov / working-with-db-nulls1.go
Last active August 21, 2018 05:03
working-with-db-nulls1
type Customer struct {
ID int
Email string
Phone string
Age int
}
func GetCustomerByEmail(db *sql.DB, email string) (*Customer, error) {
stmt, err := db.Prepare("SELECT id, email, phone, age FROM customer where email = ?")
if err != nil {
@plutov
plutov / working-with-db-nulls2.go
Created August 21, 2018 04:59
working-with-db-nulls2
type Customer struct {
ID int
Email string
Phone sql.NullString
Age sql.NullInt64
}
@plutov
plutov / working-with-db-nulls3.go
Created August 21, 2018 04:59
working-with-db-nulls3
fmt.Println(customer.Phone.Value)
@plutov
plutov / working-with-db-time-in-go1.go
Created August 21, 2018 05:05
working-with-db-time-in-go1.go
var nt mysql.NullTime
err := db.QueryRow("SELECT time FROM foo WHERE id = ?", id).Scan(&nt)
if nt.Valid {
// use nt.Time
} else {
// NULL value
}
@plutov
plutov / working-with-db-time-in-go2.go
Last active August 21, 2018 05:11
working-with-db-time-in-go2.go
db, err := sql.Open("mysql", "root:@/?parseTime=true")
var myTime time.Time
db.QueryRow("SELECT current_timestamp()").Scan(&myTime)
fmt.Println(myTime.Format(time.RFC3339))
@plutov
plutov / start-clickhouse-locally
Created August 30, 2018 03:28
start-clickhouse-locally
docker run -d -p 8123:8123 -p 9000:9000 --name some-clickhouse-server --ulimit nofile=262144:262144 yandex/clickhouse-server
@plutov
plutov / main.go
Created September 6, 2018 03:48
main.go
package main
import (
"os"
"github.com/org/repo/pkg/cli"
)
func main{
log.Fatal(cli.Run())
}
@plutov
plutov / gokit2.proto
Created September 6, 2018 03:55
gokit2.proto
syntax = "proto3";
package pb;
service Notificator {
rpc SendEmail (SendEmailRequest) returns (SendEmailReply);
}
message SendEmailRequest {
string email = 1;