Skip to main content

mono code generation


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


  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 (


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