github.com/easysoft/zendata@v0.0.0-20240513203326-705bd5a7fd67/pkg/utils/vari/var.go (about)

     1  package vari
     2  
     3  import (
     4  	"time"
     5  
     6  	consts "github.com/easysoft/zendata/internal/pkg/const"
     7  	"github.com/easysoft/zendata/internal/pkg/domain"
     8  	"github.com/easysoft/zendata/internal/pkg/model"
     9  	"gorm.io/gorm"
    10  )
    11  
    12  type GenVarType struct {
    13  	RunMode consts.RunMode
    14  	Total   int
    15  
    16  	Output           string
    17  	OutputFormat     string
    18  	TopFieldMap      map[string]domain.DefField
    19  	ExportFields     []string
    20  	ExportChildField string
    21  	ColIsNumArr      []bool
    22  
    23  	Table        string
    24  	DBType       string // database type
    25  	DBDsn        string
    26  	DBDsnParsing DBDsnData
    27  	DBClear      bool
    28  	MockDir      string
    29  
    30  	Human     bool
    31  	Trim      bool
    32  	Recursive bool
    33  
    34  	ConfigFileDir string
    35  
    36  	DefData domain.DefData
    37  	ResData map[string]map[string][]interface{}
    38  
    39  	CacheResFileToMap                  map[string]map[string][]interface{}
    40  	RandFieldSectionPathToValuesMap    map[int]map[string]interface{}
    41  	RandFieldSectionShortKeysToPathMap map[int]string
    42  
    43  	FieldNameToValuesMap map[string][]interface{}
    44  	FieldNameToFieldMap  map[string]domain.DefField
    45  
    46  	StartTime time.Time
    47  	EndTime   time.Time
    48  }
    49  
    50  var (
    51  	GlobalVars = GenVarType{
    52  		DefData:      domain.DefData{},
    53  		OutputFormat: consts.FormatText,
    54  		TopFieldMap:  map[string]domain.DefField{},
    55  
    56  		CacheResFileToMap:                  map[string]map[string][]interface{}{},
    57  		RandFieldSectionPathToValuesMap:    map[int]map[string]interface{}{},
    58  		RandFieldSectionShortKeysToPathMap: map[int]string{},
    59  
    60  		FieldNameToValuesMap: map[string][]interface{}{},
    61  		FieldNameToFieldMap:  map[string]domain.DefField{},
    62  
    63  		RunMode: consts.RunModeGen,
    64  	}
    65  )
    66  
    67  var (
    68  	Config = model.Config{Version: 1, Language: "en"}
    69  	DB     *gorm.DB
    70  
    71  	WorkDir      string
    72  	CurrFilePath string
    73  
    74  	CfgFile      string
    75  	LogDir       string
    76  	ScreenWidth  int
    77  	ScreenHeight int
    78  
    79  	RequestType string
    80  	Verbose     bool
    81  	Interpreter string
    82  
    83  	CacheParam string
    84  
    85  	DefType string
    86  
    87  	ProtoCls string
    88  
    89  	JsonResp = "[]"
    90  	Port     int
    91  
    92  	ResLoading = false
    93  	Res        = map[string]map[string][]string{}
    94  
    95  	CacheResFileToMap  = map[string]map[string][]string{}
    96  	CacheResFileToName = map[string]string{}
    97  
    98  	AgentLogDir string
    99  )
   100  
   101  // parsing from  DBDsn [added by Leo [2022/5/5]]
   102  type DBDsnData struct {
   103  	Driver   string
   104  	User     string
   105  	Password string
   106  	Host     string
   107  	Port     string
   108  	DbName   string
   109  	Code     string
   110  }