github.com/team-ide/go-dialect@v1.9.20/worker/data_source_type.go (about)

     1  package worker
     2  
     3  import "strings"
     4  
     5  type DataSourceType struct {
     6  	Name       string `json:"name"`
     7  	New        func(param *DataSourceParam) (dataSource DataSource)
     8  	FileSuffix string `json:"fileSuffix"`
     9  }
    10  
    11  var (
    12  	DataSourceTypeSql = &DataSourceType{
    13  		Name:       "sql",
    14  		FileSuffix: "sql",
    15  		New:        NewDataSourceSql,
    16  	}
    17  	DataSourceTypeExcel = &DataSourceType{
    18  		Name:       "excel",
    19  		FileSuffix: "xlsx",
    20  		New:        NewDataSourceExcel,
    21  	}
    22  	DataSourceTypeText = &DataSourceType{
    23  		Name:       "text",
    24  		FileSuffix: "txt",
    25  		New:        NewDataSourceText,
    26  	}
    27  	DataSourceTypeCsv = &DataSourceType{
    28  		Name:       "csv",
    29  		FileSuffix: "csv",
    30  		New:        NewDataSourceCsv,
    31  	}
    32  
    33  	DataSourceTypeList = []*DataSourceType{
    34  		DataSourceTypeSql,
    35  		DataSourceTypeExcel,
    36  		DataSourceTypeText,
    37  		DataSourceTypeCsv,
    38  	}
    39  )
    40  
    41  func GetDataSource(dataSourceType string) (res *DataSourceType) {
    42  	switch strings.ToLower(dataSourceType) {
    43  	case "sql":
    44  		res = DataSourceTypeSql
    45  		break
    46  	case "txt", "text":
    47  		res = DataSourceTypeText
    48  		break
    49  	case "excel":
    50  		res = DataSourceTypeExcel
    51  		break
    52  	case "csv":
    53  		res = DataSourceTypeCsv
    54  		break
    55  	}
    56  	return
    57  }