R
R
reus2017-01-17 18:29:11
go
reus, 2017-01-17 18:29:11

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

Like []article is taken from the models.article.go file
// 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
}

Tried to add in main.go import model
import (
  "github.com/gin-gonic/gin"
  "main/model"
  "net/http"
  "net/http/httptest"
  "os"
  "testing"
)

But it throws an error:
[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

Um.. and what to do with these?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
P
Papa, 2017-01-17
@reus

reus and with what fright do you have the contents of the models and handlers folders in the main package? where is it taught to write?
models - package models
handlers - package handlers
and fix the imports section in accordance with...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question