Answer the question
In order to leave comments, you need to log in
Importing packages into GO?
I don't understand what the problem is. I am writing an application according to the tutorial . When I try to call go run main.go I get:
# command-line-arguments
./main.go:12: undefined: article
./main.go:49: undefined: articleList
./main.go:54: undefined: articleList
// models.article.go
package main
type article struct {
ID int `json:"id"`
Title string `json:"title"`
Content string `json:"content"`
}
// For this demo, we're storing the article list in memory
// In a real application, this list will most likely be fetched
// from a database or from static files
var articleList = []article{
article{ID: 1, Title: "Article 1", Content: "Article 1 body"},
article{ID: 2, Title: "Article 2", Content: "Article 2 body"},
}
// Return a list of all the articles
func getAllArticles() []article {
return articleList
}
import (
"github.com/gin-gonic/gin"
"main/model"
"net/http"
"net/http/httptest"
"os"
"testing"
)
[email protected]:~/work/src/main$ go run main.go
/home/pc2/work/src/main/main.go:5:2: import "main/models" is a program, not an importable package
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question