» Go: Building Event-Driven Microservices with Kafka » 2. Producer: Web Service » 2.3 Data Models

Data Models

Data models represent the structure of the data that the API deals with. These models define the shape of the data entities exchanged between the client and the server.

For example, in this books management microservices project, a Book model can be defined:

Create domain/model/book.go:

Folder structures like domain/model/... is using 4 Layers Architecture Pattern, read more here.

package model

import "time"

// Book represents the structure of a book
type Book struct {
	ID          uint      `json:"id"`
	Title       string    `json:"title"`
	Author      string    `json:"author"`
	PublishedAt string    `json:"published_at"`
	Description string    `json:"description"`
	CreatedAt   time.Time `json:"created_at"`
}