Skip to main content

mono code generation

Overview

The mono code is generated by goctl generating model files with the specified document name. The mono does not have form statements like mysql, indexes, and so forth, so mono code generation does not need information like sql or database links.

Task Targets

  1. familiar with goctl generating mono code usage and learn about currently supported instructions and features
  2. Preliminary understanding of the format of goctl generating mono code

Preparing

  1. Complete golang installation
  2. Complete goctl installation

Code Generation

# Create workspaces and projects
$ mkdir -p ~/workspace/model/mongo && ~/workspace/model/mongo
# Generate mongo code with document name User
$ goctl model mongo --type user --dir .
# View generated files
$ ls
error.go usermodel.go usermodelgen.go usertypes.go
# view directory tree
.
├── error.go
├── usermodel.go
├── usermodelgen.go
└── usertypes.go

0 directories, 4 files

View code

package model

import (
"errors"

"github.com/zeromicro/go-zero/core/stores/mon"
)

var (
ErrNotFound = mon.ErrNotFound
ErrInvalidObjectId = errors.New("invalid objectId")
)

References