Coder Social home page Coder Social logo

webctl's Introduction

egoctl

1 Requirements

  • Go version >= 1.16.

2 Installation

bash <(curl -L https://raw.githubusercontent.com/gotomicro/egoctl/main/getlatest.sh)

通过以上脚本,可以下载protoc工具全家桶,以及ego的protoc插件和egoctl

  • /usr/local/bin/protoc
  • /usr/local/bin/protoc-gen-go
  • /usr/local/bin/protoc-gen-go-grpc
  • /usr/local/bin/protoc-gen-openapiv2
  • /usr/local/bin/protoc-gen-go-errors
  • /usr/local/bin/protoc-gen-go-http
  • /usr/local/bin/egoctl

3 快速生成代码

  • 我们第一次进入页面,先配置生成代码的模板,你也可以自己自定义自己的模板

  • 然后在进入项目页面,创建项目

  • 编写DSL

  • 创建项目的go mod
mkdir /Users/askuy/tmp/egotest1 
cd /Users/askuy/tmp/egotest1 && go mod init egotest1
  • 点击生成代码
  • 运行你的代码
cd /Users/askuy/tmp/egotest1
go mod tidy
vim config/local.toml 更改db配置
export EGO_DEBUG=true && go run main.go

4 DSL配置

package egoctl
type User struct {
	Uid int `gorm:"AUTO_INCREMENT" json:"id" dto:"" ego:"primary_key"`    // id
    UserName string `gorm:"not null" json:"userName" dto:""` // 昵称
}

5 模板配置

5.1 根据模型设置模板

DSL配置

package egoctl
type User struct {
	Uid int `gorm:"AUTO_INCREMENT" json:"id" dto:"" ego:"primary_key"`                      // id
    UserName string `gorm:"not null" json:"userName" dto:""` // 昵称
}

5.2 获取主键

模版配置

{{modelSchemas|fieldsGetPrimaryKey|snakeString}}

5.3 生成结构体

模板配置

type {{modelName|upperFirst}} struct {
	{% for value in modelSchemas %}
	{{value.FieldName}} {{value.FieldType}} `gorm:"{{value|fieldGetTag:"gorm"}}"` {{value.Comment}}
	{% endfor %}
}

5.4 判断某字段是否存在

模板配置

{% if modelSchemas|fieldsExist:Uid %}
{% endif %}

6 根据单个字段设置模板

DSL配置

type User struct {
	Uid int `gorm:"AUTO_INCREMENT" json:"id" dto:"" ego:"primary_key"`                      // id
    UserName string `gorm:"not null" json:"userName" dto:""` // 昵称
}

6.1 获取某个字段的驼峰(常用于JSON,前后端对接)

{{value.FieldName|camelString|lowerFirst}}
UserName  变成   userName

6.2 获取某个字段的蛇形(常用于数据库)

{{value.FieldName|snakeString|lowerFirst}}
UserName  变成   user_name

webctl's People

Contributors

askuy avatar wujunze avatar sevennt avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.