Documentation ¶
Index ¶
- Variables
- func ArticleJSON(database DB) ([]byte, error)
- func CategoriesJSON(rows *sql.Rows) ([]byte, error)
- func OneArticleJSON(database DB, id uint64) ([]byte, error)
- func OneCategoryJSON(databse DB, queryStmt string, args ...interface{}) ([]byte, error)
- type Articles
- type Categories
- type Comment
- type DB
- func (d *DB) Close()
- func (d DB) Exec(queryStmt string, args ...interface{}) error
- func (d DB) ExecStmt(stmt *sql.Stmt, args ...interface{}) error
- func (d DB) Handler() *sql.DB
- func (d DB) Prepare(queryStmt string) (*sql.Stmt, error)
- func (d DB) Query(queryStmt string, args ...interface{}) (*sql.Rows, error)
- type ErrSQL
- type Image
- type Payload
- type User
Constants ¶
This section is empty.
Variables ¶
var ( // ErrNoContent no body response sql interogation ErrNoContent = errors.New("No content found") )
Functions ¶
func ArticleJSON ¶
ArticleJSON return article JSON format from joining multiple tables Article, Cateogries, Image, Comment, Users.
func CategoriesJSON ¶
CategoriesJSON readss from rows object and return all the info in JSON frormat
func OneArticleJSON ¶
OneArticleJSON makes query and responds with one article in json format
Types ¶
type Articles ¶
type Articles struct { ID int `json: "ID"` Title string `json: "Title"` Time string `json: "Time"` Author string `json: "Author"` Content string `json: "Content"` Category string `json: "Category"` Image []Image `json: "Image"` Comments []Comment `json "Comments"` }
Articles struct serializable json response
type Categories ¶
Categories struct serializable json response
type Comment ¶
type Comment struct { ID uint64 `json : "ID"` User User `json: "User"` Time string `json : "Time"` Content string `json : "Content"` }
Comment struct serializable json response
type DB ¶
type DB struct {
// contains filtered or unexported fields
}
DB struct pointer to sql.DB sql.Open return handler for database database/sql package manages a pool of connections in the background and dosen't open any connections util you need them. Before making queries we test with handler.Ping() or with err, _ = db.Exec("DO 1")
if err != nil { panic(err.Error()) }
func NewOpen ¶
NewOpen returns a new db type object basically returns a db object to make a connection to mysql/maria db
type ErrSQL ¶
type ErrSQL struct {
Message string `json: "Message"`
}
ErrSQL struct for internal purpose error handleing
type Payload ¶
type Payload struct {
Data interface{}
}
Payload json fromat
func NewPayload ¶
func NewPayload(d interface{}) Payload
NewPayload return new JSON response payload