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 main | |
| import ( | |
| "fmt" | |
| "log" | |
| "net/http" | |
| ) | |
| // data variable | |
| var messageChan chan 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 repository | |
| type Repository interface { | |
| ReadExamples() ([]Example, error) | |
| ReadExampleByID(id int64) (Example, error) | |
| WriteExample(example Example) error | |
| UpdateExample(example Example) error | |
| RemoveExampleByID(id int64) error | |
| } |
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 repository | |
| type Example struct { | |
| ID int64 | |
| Content string | |
| } | |
| func (e *Example) FastScan() []interface{} { | |
| return []interface{}{ | |
| &e.ID, |
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 repository | |
| import ( | |
| "database/sql" | |
| ) | |
| type repo struct { | |
| db *sql.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
| package repository | |
| func (r repository) ReadExampleByID(id int64) (Example, error) { | |
| const query = `SELECT * FROM example WHERE id = ?` | |
| var example Example | |
| stmt, err := r.db.Prepare(query) | |
| if err != nil { | |
| return Example{}, err | |
| } |
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 repository | |
| func (r repo) ReadExampleByID(id int64) (Example, error) { | |
| const query = `SELECT * FROM example WHERE id = ?` | |
| var example Example | |
| stmt, err := r.db.Prepare(query) | |
| if err != nil { | |
| return Example{}, err | |
| } |
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 repository | |
| func (r repo) ReadExamples() ([]Example, error) { | |
| const query = `SELECT * FROM example` | |
| var examples []Example | |
| stmt, err := r.db.Prepare(query) | |
| if err != nil { | |
| return nil, err | |
| } |
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 repository | |
| func (r repo) RemoveExampleByID(id int64) error { | |
| const query = `DELETE FROM example WHERE id = ?` | |
| stmt, err := r.db.Prepare(query) | |
| if err != nil { | |
| return err | |
| } |
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 repository | |
| func (r repo) UpdateExample(example Example) error { | |
| const query = `UPDATE example SET content = ? WHERE id = ?` | |
| stmt, err := r.db.Prepare(query) | |
| if err != nil { | |
| return err | |
| } |
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 repository | |
| func (r repo) WriteExample(example Example) error { | |
| const query = `INSERT INTO example(content) VALUES (?)` | |
| stmt, err := r.db.Prepare(query) | |
| if err != nil { | |
| return err | |
| } |
OlderNewer