Avatar ·

Cyclic import in Go: how to fix the "import cycle not allowed" error

Hello everyone! I'm new to Go and I've encountered a problem that I can't seem to solve. I'm writing a small task management application (to-do list). I have two packages: `models` and `services`. In the `models` package, I defined the `Task` struct and the `Validate` function, which checks the correctness of a task. In the `services` package, I want to implement the logic for adding a task to the database, and before saving, I need to call `Validate` from `models`. Here's an example code: **models/task.go:** ```go package models import "errors" type Task struct { ID int Name string } func Validate(t Task) error { if t.Name == "" { return errors.New("name is required") } return nil } ``` **services/task_service.go:** ```go package services import (