-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
52 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,32 @@ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
"github.com/spf13/cobra" | ||
"trojan/web" | ||
) | ||
|
||
var port int | ||
var ( | ||
port int | ||
ssl bool | ||
) | ||
|
||
// webCmd represents the web command | ||
var webCmd = &cobra.Command{ | ||
Use: "web", | ||
Short: "以web方式启动", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
web.Start(port) | ||
if ssl && port == 80 { | ||
fmt.Println("启动web服务失败!") | ||
fmt.Println("以https方式运行必须传参-p来指定https的运行端口(不能为80)") | ||
return | ||
} | ||
web.Start(port, ssl) | ||
}, | ||
} | ||
|
||
func init() { | ||
webCmd.Flags().IntVarP(&port, "port", "p", 80, "web服务启动端口") | ||
webCmd.Flags().BoolVarP(&ssl, "ssl", "", false, "web服务是否以https方式运行") | ||
rootCmd.AddCommand(webCmd) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters