前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >在 Golang 中像 Laravel 的 Artisan 一样使用命令行,Goravel 带你找回熟悉的味道

在 Golang 中像 Laravel 的 Artisan 一样使用命令行,Goravel 带你找回熟悉的味道

原创
作者头像
韩同学的简单逻辑
发布2022-04-25 18:00:09
8090
发布2022-04-25 18:00:09
举报
文章被收录于专栏:Goravel

Laravel 中的 Artisan 命令行是这样

代码语言:txt
复制
// 创建命令
php artisan make:command SendEmails
// 运行命令
php artisan mail:send
// 使用参数
php artisan mail:send hello
// 使用选项
php artisan mail:send --mail=abc@qq.com

Goravel 中的 Artisan 命令行也一样

代码语言:txt
复制
// 创建命令
go run . artisan make:command SendEmails
// 运行命令
go run . artisan mail:send
// 使用参数
go run . artisan mail:send hello
// 使用选项
go run . artisan mail:send --mail abc@qq.com

就连 struct 的定义都是满满的回忆:

代码语言:txt
复制
package commands

import (
  "github.com/goravel/framework/contracts/console"
  "github.com/urfave/cli/v2"
)

type SendEmails struct {
}

//Signature The name and signature of the console command.
func (receiver *SendEmails) Signature() string {
  return "emails"
}

//Description The console command description.
func (receiver *SendEmails) Description() string {
  return "Command description"
}

//Extend The console command extend.
func (receiver *SendEmails) Extend() console.CommandExtend {
  return console.CommandExtend{}
}

//Handle Execute the console command.
func (receiver *SendEmails) Handle(c *cli.Context) error {
  return nil
}

熟悉的配方,原来的味道。PHPer 极速切换,Goer 的福音。 欢迎 star 与 issues。

关于 Goravel

Goravel 是一个功能完备、具有良好扩展能力的 Web 应用程序框架。 作为一个起始脚手架帮助 Golang 开发者快速构建自己的应用。

项目地址:https://github.com/goravel/goravel

文档地址:www.goravel.dev

golang横.png
golang横.png

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • Laravel 中的 Artisan 命令行是这样
  • Goravel 中的 Artisan 命令行也一样
  • 关于 Goravel
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档