Last active
August 18, 2021 05:09
-
-
Save mehmetron/d2528df63f9accc23fc7c5f134bbf7cd to your computer and use it in GitHub Desktop.
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 Env struct { | |
articles ArticleModel | |
} | |
type ArticleModel struct { | |
DB *sqlx.DB | |
} | |
func (env *Env) GetAllArticles(w http.ResponseWriter, r *http.Request) { | |
articles, err := env.articles.GetAllArticles() | |
if err != nil { | |
fmt.Println("19 ", err) | |
} | |
err = utils.WriteJSON(w, http.StatusOK, articles, nil) | |
if err != nil { | |
fmt.Println(err) | |
} | |
} | |
func (m ArticleModel) GetAllArticles() ([]Articles, error) { | |
var articles []Articles | |
query := `SELECT id, name, content FROM article ORDER BY name ASC` | |
err := m.DB.Select(&articles, query) | |
if err != nil { | |
return nil, err | |
} | |
fmt.Println("80 ", articles) | |
return articles, nil | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment