I’ve my structure as bellow:
in the main.go
I import both modules lib
and models
as:
package main
import (
"aging/lib"
"aging/models"
)
Each file at folder models
start by:
package models
And none of the files in the models
have any import statement of lib
Each file at folder lib
start by:
package lib
And none of the files in the lib
have any import statement of models
Things are running smoothly.
I wanted to use a model in one of the files at lib
so at that file (the one in the lib) I wrote:
package lib
import (
"aging/models"
"encoding/csv"
"log"
"strconv"
)
// Write the data to the selected csv file
func WriteOutputs(data models.Inventories, file *csv.Writer) { }
Then things collapsed and I got the error below:
import cycle not allowed
package aging
imports aging/lib
imports aging/models
imports aging/lib
i do not understand how this cycle happen, as I see my app it is as below:
main ----> models
\
\--> lib ------> models
Where is my misunderstanding?