func (g *Gen) Build(config *Config) error {
	if config.InstanceName == "" {
		config.InstanceName = swag.Name
	}
	searchDirs := strings.Split(config.SearchDir, ",")
	for _, searchDir := range searchDirs {
		if _, err := os.Stat(searchDir); os.IsNotExist(err) {
			return fmt.Errorf("dir: %s does not exist", searchDir)
		}
	}
	log.Println("Generate swagger docs....")
	p := swag.New(swag.SetMarkdownFileDirectory(config.MarkdownFilesDir),
		swag.SetExcludedDirsAndFiles(config.Excludes),
		swag.SetCodeExamplesDirectory(config.CodeExampleFilesDir),
		swag.SetStrict(config.Strict))
	p.PropNamingStrategy = config.PropNamingStrategy
	p.ParseVendor = config.ParseVendor
	p.ParseDependency = config.ParseDependency
	p.ParseInternal = config.ParseInternal
	if err := p.ParseAPIMultiSearchDir(searchDirs, config.MainAPIFile, config.ParseDepth); err != nil {
		return err
	}
	swagger := p.GetSwagger()
	b, err := g.jsonIndent(swagger)
	if err != nil {
		return err
	}
	if err := os.MkdirAll(config.OutputDir, os.ModePerm); err != nil {
		return err
	}
	absOutputDir, err := filepath.Abs(config.OutputDir)
	if err != nil {
		return err
	}
	packageName := filepath.Base(absOutputDir)
	docFileName := filepath.Join(config.OutputDir, "docs.go")
	jsonFileName := filepath.Join(config.OutputDir, "swagger.json")
	yamlFileName := filepath.Join(config.OutputDir, "swagger.yaml")
	docs, err := os.Create(docFileName)
	if err != nil {
		return err
	}
	defer docs.Close()
	err = g.writeFile(b, jsonFileName)
	if err != nil {
		return err
	}
	y, err := g.jsonToYAML(b)
	if err != nil {
		return fmt.Errorf("cannot convert json to yaml error: %s", err)
	}
	err = g.writeFile(y, yamlFileName)
	if err != nil {
		return err
	}
	err = g.writeGoDoc(packageName, docs, swagger, config)
	if err != nil {
		return err
	}
	log.Printf("create docs.go at %+v", docFileName)
	log.Printf("create swagger.json at %+v", jsonFileName)
	log.Printf("create swagger.yaml at %+v", yamlFileName)
	return nil
}
Build builds swagger json file  for given searchDir and mainAPIFile. Returns json
package gen
import (
	"bytes"
	"encoding/json"
	"fmt"
	"go/format"
	"io"
	"log"
	"os"
	"path/filepath"
	"strings"
	"text/template"
	"time"
	"github.com/ghodss/yaml"
	"github.com/go-openapi/spec"
	"github.com/swaggo/swag"
)
type Gen struct {
	jsonIndent func(data interface{}) ([]byte, error)
	jsonToYAML func(data []byte) ([]byte, error)
}
func New() *Gen {
	return &Gen{
		jsonIndent: func(data interface{}) ([]byte, error) {
			return json.MarshalIndent(data, "", "    ")
		},
		jsonToYAML: yaml.JSONToYAML,
	}
}
type Config struct {
	SearchDir string
	Excludes string
	OutputDir string
	MainAPIFile string
	PropNamingStrategy string
	ParseVendor bool
	ParseDependency bool
	ParseInternal bool
	Strict bool
	MarkdownFilesDir string
	GeneratedTime bool
	CodeExampleFilesDir string
	ParseDepth int
	InstanceName string
}