Implementing the Model

The createNewArticle function should create a new article based on the input supplied to it, add it to the list of articles and return it. This can be done as shown below:

// models.article.go

func createNewArticle(title, content string) (*article, error) {
    a := article{ID: len(articleList) + 1, Title: title, Content: content}

    articleList = append(articleList, a)

    return &a, nil
}

Now, run the following command in your shell to test that this function behaves as expected:

go test -run=TestCreateNewArticle

This test should run successfully and show the following message:

PASS
ok      github.com/demo-apps/go-gin-app 0.006s

results matching ""

    No results matching ""