This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| type UserFactory struct { | |
| db *reform.DB | |
| } | |
| func NewUserFactory(db *sql.DB) *UserFactory { | |
| return &UserFactory{ | |
| db: NewDB(db), | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| type Option func(*Client) | |
| func SetHTTPClient(httpClient *http.Client) Option { | |
| return func(cli *Client) { | |
| cli.httpClient = httpClient | |
| } | |
| } | |
| func NewClient(api, secret string, options ...Option) *Client { | |
| cli := Client{ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const ( | |
| okResponse = `{ | |
| "users": [ | |
| {"id": 1, "name": "Roman"}, | |
| {"id": 2, "name": "Dmitry"} | |
| ] | |
| }` | |
| ) | |
| func TestClientGetUsers(t *testing.T) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| func testingHTTPClient(handler http.Handler) (*http.Client, func()) { | |
| s := httptest.NewServer(handler) | |
| cli := &http.Client{ | |
| Transport: &http.Transport{ | |
| DialContext: func(_ context.Context, network, _ string) (net.Conn, error) { | |
| return net.Dial(network, s.Listener.Addr().String()) | |
| }, | |
| }, | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package example | |
| import ( | |
| "encoding/json" | |
| "fmt" | |
| "net/http" | |
| "time" | |
| "github.com/pkg/errors" | |
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| " vim hardmode | |
| inoremap <Up> <NOP> | |
| inoremap <Down> <NOP> | |
| inoremap <Left> <NOP> | |
| inoremap <Right> <NOP> | |
| inoremap <Del> <NOP> | |
| inoremap <BS> <NOP> | |
| noremap <Up> <NOP> | |
| noremap <Down> <NOP> | |
| noremap <Left> <NOP> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import nullable "github.com/romanyx/nullable" | |
| // BlogUpdateRequest Blog update request | |
| // swagger:model BlogUpdateRequest | |
| type BlogUpdateRequest struct { | |
| // Blog markdown body | |
| // Required: true | |
| Markdown *string `json:"markdown"` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| "BlogUpdateRequest": { | |
| "title": "Blog update request", | |
| "type": "object", | |
| "properties": { | |
| "title": { | |
| "description": "Blog title", | |
| "type": "string" | |
| }, | |
| "markdown": { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| "NullableInt": { | |
| "type": "integer", | |
| "example": 1525360737, | |
| "x-go-type": { | |
| "import": { | |
| "package": "github.com/romanyx/nullable" | |
| }, | |
| "type": "Int" | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| func updateBlog(db *sql.DB, id int64, req *models.BlogUpdateRequest) error { | |
| columns := []string{"title", "body"} | |
| values := []interface{*req.Title, *req.Body} | |
| if req.PublishedAt.Present { | |
| if req.PublishedAt.Valid { | |
| values = append(values, req.PublishedAt.Value) | |
| } else { | |
| values = append(values, sql.NullInt64{}) | |
| } |