swagger

package
v0.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 27, 2020 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var GenCommand = &cobra.Command{
	Use:   "gen",
	Short: "generate swagger file, contain swagger.yaml, doc.go",
	Run: func(c *cobra.Command, args []string) {
		container := commandUtil.GetContainer(c.Root())
		appService := container.MustMake(contract.AppKey).(contract.App)

		outputDir := filepath.Join(appService.BasePath(), "app", "http", "swagger")

		conf := &gen.Config{
			SearchDir:          "./app/http/",
			Excludes:           "",
			OutputDir:          outputDir,
			MainAPIFile:        "swagger.go",
			PropNamingStrategy: "",
			ParseVendor:        false,
			ParseDependency:    false,
			ParseInternal:      false,
			MarkdownFilesDir:   "",
			GeneratedTime:      false,
		}
		err := gen.New().Build(conf)
		if err != nil {
			fmt.Println(err)
		}
	},
}

envCommand show current envionment

View Source
var IndexCommand = &cobra.Command{
	Use:   "swagger",
	Short: "swagger operator",
	RunE: func(c *cobra.Command, args []string) error {
		if len(args) == 0 {
			c.Help()
		}
		return nil
	},
}
View Source
var ServeCommand = &cobra.Command{
	Use:   "serve",
	Short: "use gen serve",
	RunE: func(c *cobra.Command, args []string) error {
		container := commandUtil.GetContainer(c.Root())
		appService := container.MustMake(contract.AppKey).(contract.App)

		r := gin.Default()

		hadeURL, err := url.Parse(address)
		if err != nil {
			return err
		}
		address := fmt.Sprintf("%s:%s", hadeURL.Hostname(), hadeURL.Port())

		jsonFolder := filepath.Join(appService.BasePath(), "app", "http", "swagger")

		r.Static("/swagger_gen/", jsonFolder)
		swaggerGenUrl := ginSwagger.URL("/swagger_gen/swagger.json")
		r.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler, swaggerGenUrl))

		fmt.Println("swagger success: http://" + address + "/swagger/index.html")
		fmt.Println("if you want to replace, remember use command: swagger gen")
		r.Run(address)
		return nil
	},
}

envCommand show current envionment

Functions

func InitServeCommand

func InitServeCommand() *cobra.Command

初始化Dev命令

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL