Best Keploy code snippet using model.String
MenuModel_gen.go
Source:MenuModel_gen.go
...217// GetLabel (get_label)218// Returns the label for the specified |command_id| or NULL if not found.219// The resulting string must be freed by calling cef_string_userfree_free().220func (d *MenuModel) GetLabel(commandID int32) string {221 return cefuserfreestrToString(C.gocef_menu_model_get_label(d.toNative(), C.int(commandID), d.get_label))222}223// GetLabelAt (get_label_at)224// Returns the label at the specified |index| or NULL if not found due to225// invalid range or the index being a separator.226// The resulting string must be freed by calling cef_string_userfree_free().227func (d *MenuModel) GetLabelAt(index int32) string {228 return cefuserfreestrToString(C.gocef_menu_model_get_label_at(d.toNative(), C.int(index), d.get_label_at))229}230// SetLabel (set_label)231// Sets the label for the specified |command_id|. Returns true (1) on success.232func (d *MenuModel) SetLabel(commandID int32, label string) int32 {233 label_ := C.cef_string_userfree_alloc()234 setCEFStr(label, label_)235 defer func() {236 C.cef_string_userfree_free(label_)237 }()238 return int32(C.gocef_menu_model_set_label(d.toNative(), C.int(commandID), (*C.cef_string_t)(label_), d.set_label))239}240// SetLabelAt (set_label_at)241// Set the label at the specified |index|. Returns true (1) on success.242func (d *MenuModel) SetLabelAt(index int32, label string) int32 {...
DataSampel.go
Source:DataSampel.go
1package main2import (3 . "eaciit/secsampeldata/Datahelper"4 // "fmt"5 // . "github.com/ahmetalpbalkan/go-linq"6 "github.com/metakeule/fmtdate"7 // "github.com/tealeg/xlsx"8 // "gopkg.in/mgo.v2/bson"9 //"bytes"10 //"encoding/csv"11 // "io/ioutil"12 // "math"13 //"os"14 "math/rand"15 "strconv"16 // "strings"17 "time"18)19func main() {20 // sampelAssetClass()21 // sampelAssetLevel()22 // SampleLocation()23 // SampleAssetType()24 // SamplePlant()25 sampelAsset()26 // sampleAssetPlacements()27 // sampleAssetPerformance()28 // sampleAssetMaintenance()29 // sampleAssetFinancial()30 // sampleAssetMaintenanceSchedule()31}32type ModelAssetClass struct {33 Code string34 ClassName string35}36type ModelAssetLevel struct {37 Code string38 LevelName string39}40type ModelSampleLocation struct {41 Country string42 City string43 Longitude float6444 Latitude float6445}46type ModelSampleAssetType struct {47 Code string48 TypeName string49}50type ModelSamplePlant struct {51 Name string52 Code string53 Location ModelSampleLocation54}55func sampelAssetClass() {56 //fmt.Println("Coba")57 for i := 1; i <= 5; i++ {58 var model ModelAssetClass59 model.Code = "Class" + strconv.Itoa(i)60 model.ClassName = "Class " + strconv.Itoa(i)61 Save("SampleAssetClass", model)62 }63}64func sampelAssetLevel() {65 for i := 1; i <= 5; i++ {66 var model ModelAssetLevel67 model.Code = "Level" + strconv.Itoa(i)68 model.LevelName = "Level " + strconv.Itoa(i)69 Save("SampleAssetLevel", model)70 }71}72func SampleLocation() {73 for i := 1; i <= 5; i++ {74 var model ModelSampleLocation75 model.Country = "Country" + strconv.Itoa(i)76 model.City = "City" + strconv.Itoa(i)77 model.Longitude = 078 model.Latitude = 079 Save("SampleLocation", model)80 }81}82func SampleAssetType() {83 for i := 1; i <= 5; i++ {84 var model ModelSampleAssetType85 model.Code = "Type" + strconv.Itoa(i)86 model.TypeName = "Type " + strconv.Itoa(i)87 Save("SampleAssetType", model)88 }89}90func SamplePlant() {91 var ResultLoc []ModelSampleLocation92 PopulateAsObject(&ResultLoc, "SampleLocation", nil, 0, 0)93 for i := 1; i <= 5; i++ {94 var model ModelSamplePlant95 model.Name = "Plant " + strconv.Itoa(i)96 model.Code = "Plant" + strconv.Itoa(i)97 model.Location = ResultLoc[rand.Intn(len(ResultLoc))]98 Save("SamplePlant", model)99 }100}101type ModelAsset struct {102 Code string103 Name string104 Manufacturer string105 ManufacturedYear int106 Class ModelAssetClass107 Type ModelSampleAssetType108 Level ModelAssetLevel109 NormalCapacity int110 Notes string111 PurchaseDate time.Time112 PurchaseCost float64113 PurchaseCondition string114 PurchaseVendor string115 PurchaseDiscount int116 EstimatedUsage int117 AmortizationRate int118 DepresiationRate int119 LatestStatus string120}121func sampelAsset() {122 var (123 ResultClass []ModelAssetClass124 ResultType []ModelSampleAssetType125 ResultLevel []ModelAssetLevel126 dateRand string127 )128 ManufacturedYearVal := [2]int{2015, 2014}129 CapacityVal := [8]int{15, 17, 10, 15, 22, 12, 14, 20}130 Monthstring := [12]string{"01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12"}131 CostVal := [8]float64{1500, 1700, 1000, 1500, 2200, 1200, 1400, 2000}132 ConditionVal := [2]string{"New", "Used"}133 ManufacturerVal := [3]string{"eaciit", "pertamina", "telkom"}134 DiskonVal := [4]int{15, 20, 25, 50}135 StatusVal := [4]string{"Used", "Broken", "Available", "Other"}136 PopulateAsObject(&ResultClass, "SampleAssetClass", nil, 0, 0)137 PopulateAsObject(&ResultType, "SampleAssetType", nil, 0, 0)138 PopulateAsObject(&ResultLevel, "SampleAssetLevel", nil, 0, 0)139 for i := 1; i <= 100; i++ {140 var (141 model ModelAsset142 )143 model.Code = "Asset" + strconv.Itoa(i)144 model.Name = "Asset " + strconv.Itoa(i)145 model.Manufacturer = ManufacturerVal[rand.Intn(len(ManufacturerVal))]146 model.ManufacturedYear = ManufacturedYearVal[rand.Intn(len(ManufacturedYearVal))]147 model.Class = ResultClass[rand.Intn(len(ResultClass))]148 model.Type = ResultType[rand.Intn(len(ResultType))]149 model.Level = ResultLevel[rand.Intn(len(ResultLevel))]150 model.NormalCapacity = CapacityVal[rand.Intn(len(CapacityVal))]151 model.Notes = "Note " + strconv.Itoa(i)152 dateRand = strconv.Itoa(ManufacturedYearVal[rand.Intn(len(ManufacturedYearVal))]) + "/" + Monthstring[rand.Intn(len(Monthstring))] + "/" + strconv.Itoa(CapacityVal[rand.Intn(len(CapacityVal))]) + " 00:00:00"153 model.PurchaseDate, _ = fmtdate.Parse("YYYY/MM/DD hh:mm:ss", dateRand)154 model.PurchaseCost = CostVal[rand.Intn(len(CostVal))]155 model.PurchaseCondition = ConditionVal[rand.Intn(len(ConditionVal))]156 model.PurchaseVendor = "eaciit"157 model.PurchaseDiscount = DiskonVal[rand.Intn(len(DiskonVal))]158 // dateRand = strconv.Itoa(ManufacturedYearVal[rand.Intn(len(ManufacturedYearVal))]) + "/" + Monthstring[rand.Intn(len(Monthstring))] + "/" + strconv.Itoa(CapacityVal[rand.Intn(len(CapacityVal))]) + " 00:00:00"159 model.EstimatedUsage = rand.Intn(12 + 1)160 if model.EstimatedUsage == 0 {161 model.EstimatedUsage = 1162 }163 model.AmortizationRate = DiskonVal[rand.Intn(len(DiskonVal))]164 model.DepresiationRate = DiskonVal[rand.Intn(len(DiskonVal))]165 model.LatestStatus = StatusVal[rand.Intn(len(StatusVal))]166 // fmt.Println(model.PurchaseDate)167 Save("SampleAsset", model)168 }169}170type ModelAssetPlacements struct {171 Plants ModelSamplePlant172 Assets ModelAsset173 PlacedDate time.Time174 PlacedCondition string175 ReturnDate time.Time176 ReturnCondition string177 LatestAvailability int178}179func sampleAssetPlacements() {180 var (181 ResultPlant []ModelSamplePlant182 ResultAsset []ModelAsset183 dateRand string184 )185 ManufacturedYearVal := [2]int{2015, 2014}186 Monthstring := [12]string{"01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12"}187 CapacityVal := [8]int{15, 17, 10, 15, 22, 12, 14, 20}188 ConditionVal := [2]string{"New", "Used"}189 PopulateAsObject(&ResultPlant, "SamplePlant", nil, 0, 0)190 PopulateAsObject(&ResultAsset, "SampleAsset", nil, 0, 0)191 for i := 1; i <= 100; i++ {192 var model ModelAssetPlacements193 model.Plants = ResultPlant[rand.Intn(len(ResultPlant))]194 model.Assets = ResultAsset[rand.Intn(len(ResultAsset))]195 dateRand = strconv.Itoa(ManufacturedYearVal[rand.Intn(len(ManufacturedYearVal))]) + "/" + Monthstring[rand.Intn(len(Monthstring))] + "/" + strconv.Itoa(CapacityVal[rand.Intn(len(CapacityVal))]) + " 00:00:00"196 model.PlacedDate, _ = fmtdate.Parse("YYYY/MM/DD hh:mm:ss", dateRand)197 model.PlacedCondition = ConditionVal[rand.Intn(len(ConditionVal))]198 dateRand = strconv.Itoa(ManufacturedYearVal[rand.Intn(len(ManufacturedYearVal))]) + "/" + Monthstring[rand.Intn(len(Monthstring))] + "/" + strconv.Itoa(CapacityVal[rand.Intn(len(CapacityVal))]) + " 00:00:00"199 model.ReturnDate, _ = fmtdate.Parse("YYYY/MM/DD hh:mm:ss", dateRand)200 model.ReturnCondition = ConditionVal[rand.Intn(len(ConditionVal))]201 model.LatestAvailability = CapacityVal[rand.Intn(len(CapacityVal))]202 Save("SampleAssetPlacements", model)203 }204}205type ModelAssetPerformance struct {206 Assets ModelAsset207 StartsTime time.Time208 StopTime time.Time209 Duration int210 Availability int211 UtilizedDuration int212 UtilizedPower int213}214func sampleAssetPerformance() {215 var (216 ResultAsset []ModelAsset217 dateRand string218 )219 ManufacturedYearVal := [2]int{2015, 2014}220 Monthstring := [12]string{"01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12"}221 CapacityVal := [8]int{15, 17, 10, 15, 22, 12, 14, 20}222 hourRand := [5]time.Duration{3, 5, 6, 9, 8}223 PopulateAsObject(&ResultAsset, "SampleAsset", nil, 0, 0)224 for i := 1; i <= 100; i++ {225 var (226 model ModelAssetPerformance227 startrand time.Time228 hourVal time.Duration229 )230 model.Assets = ResultAsset[rand.Intn(len(ResultAsset))]231 dateRand = strconv.Itoa(ManufacturedYearVal[rand.Intn(len(ManufacturedYearVal))]) + "/" + Monthstring[rand.Intn(len(Monthstring))] + "/" + strconv.Itoa(CapacityVal[rand.Intn(len(CapacityVal))]) + " 00:00:00"232 // model.StartsTime, _ = fmtdate.Parse("YYYY/MM/DD hh:mm:ss", dateRand)233 startrand, _ = fmtdate.Parse("YYYY/MM/DD hh:mm:ss", dateRand)234 // dateRand = strconv.Itoa(ManufacturedYearVal[rand.Intn(len(ManufacturedYearVal))]) + "/" + Monthstring[rand.Intn(len(Monthstring))] + "/" + strconv.Itoa(CapacityVal[rand.Intn(len(CapacityVal))]+3) + " 00:00:00"235 hourVal = hourRand[rand.Intn(len(hourRand))]236 model.StartsTime = startrand.Add(hourVal * time.Hour)237 hourVal = hourRand[rand.Intn(len(hourRand))]238 model.StopTime = model.StartsTime.Add(hourVal * time.Hour)239 model.Duration = model.StopTime.Hour() - model.StartsTime.Hour()240 // fmt.Println(rand.Intn(5))241 model.Availability = CapacityVal[rand.Intn(len(CapacityVal))]242 model.UtilizedDuration = rand.Intn(model.Duration + 1)243 if model.UtilizedDuration == 0 {244 model.UtilizedDuration = 1245 }246 model.UtilizedPower = CapacityVal[rand.Intn(len(CapacityVal))]247 Save("SampleAssetPerformance", model)248 }249}250type ModelAssetMaintenance struct {251 Assets ModelAsset252 StartsTime time.Time253 StopTime time.Time254 Duration int255 MaintenanceStatus string256 MaintenanceBy string257 MaintenanceGroup string258 ChangedParts string259 CausedBy string260 ConditionBefore string261 ConditionAfter string262 ConditionPercentage int263 Notes string264}265func sampleAssetMaintenance() {266 var (267 ResultAsset []ModelAsset268 dateRand string269 )270 ManufacturedYearVal := [2]int{2015, 2014}271 Monthstring := [12]string{"01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12"}272 CapacityVal := [8]int{15, 17, 10, 15, 22, 12, 14, 20}273 StatusVal := [2]string{"Scheduled", "UnPlanned"}274 PersenVal := [7]int{15, 20, 25, 50, 70, 75, 80}275 hourRand := [5]time.Duration{3, 5, 6, 9, 8}276 GroupVal := [6]string{"Failure", "Renewal Overhauls", "Risk Limited", "Operating Time", "Condition Based", "Others"}277 PopulateAsObject(&ResultAsset, "SampleAsset", nil, 0, 0)278 for i := 1; i <= 100; i++ {279 var (280 model ModelAssetMaintenance281 startrand time.Time282 hourVal time.Duration283 )284 model.Assets = ResultAsset[rand.Intn(len(ResultAsset))]285 dateRand = strconv.Itoa(ManufacturedYearVal[rand.Intn(len(ManufacturedYearVal))]) + "/" + Monthstring[rand.Intn(len(Monthstring))] + "/" + strconv.Itoa(CapacityVal[rand.Intn(len(CapacityVal))]) + " 00:00:00"286 // model.StartsTime, _ = fmtdate.Parse("YYYY/MM/DD hh:mm:ss", dateRand)287 startrand, _ = fmtdate.Parse("YYYY/MM/DD hh:mm:ss", dateRand)288 // dateRand = strconv.Itoa(ManufacturedYearVal[rand.Intn(len(ManufacturedYearVal))]) + "/" + Monthstring[rand.Intn(len(Monthstring))] + "/" + strconv.Itoa(CapacityVal[rand.Intn(len(CapacityVal))]+3) + " 00:00:00"289 hourVal = hourRand[rand.Intn(len(hourRand))]290 model.StartsTime = startrand.Add(hourVal * time.Hour)291 hourVal = hourRand[rand.Intn(len(hourRand))]292 model.StopTime = model.StartsTime.Add(hourVal * time.Hour)293 model.Duration = model.StopTime.Hour() - model.StartsTime.Hour()294 model.MaintenanceStatus = StatusVal[rand.Intn(len(StatusVal))]295 model.MaintenanceBy = "eaciit"296 model.MaintenanceGroup = GroupVal[rand.Intn(len(GroupVal))]297 model.ChangedParts = "Parts " + strconv.Itoa(i)298 model.CausedBy = "Broken"299 model.ConditionBefore = "Good"300 model.ConditionAfter = "Damaged"301 model.ConditionPercentage = PersenVal[rand.Intn(len(PersenVal))]302 model.Notes = "Note " + strconv.Itoa(i)303 Save("SampleAssetMaintenance", model)304 }305}306type ModelAssetFinancial struct {307 Assets ModelAsset308 Period time.Time309 Revenues float64310 OperationalCost float64311 MaintenanceCost float64312 InsuranceCost float64313 OtherCost float64314 SalvageValue float64315 AcquisitionCost float64316 SustainingCapital float64317}318func sampleAssetFinancial() {319 var (320 ResultAsset []ModelAsset321 dateRand string322 Monthstring [6]string323 YearVal int324 )325 ManufacturedYearVal := [2]int{2015, 2014}326 CapacityVal := [8]int{15, 17, 10, 15, 22, 12, 14, 20}327 RevenuesVal := [8]float64{1500, 1700, 1000, 1500, 2200, 1200, 1400, 2000}328 OptCostVal := [8]float64{1500, 1700, 1000, 1500, 2200, 1200, 1400, 2000}329 MaintCostVal := [8]float64{1500, 1700, 1000, 1500, 2200, 1200, 1400, 2000}330 InsCostVal := [8]float64{1500, 1700, 1000, 1500, 2200, 1200, 1400, 2000}331 OthCostVal := [8]float64{1500, 1700, 1000, 1500, 2200, 1200, 1400, 2000}332 SalvageVal := [8]float64{1500, 1700, 1000, 1500, 2200, 1200, 1400, 2000}333 AcqCostVal := [8]float64{1500, 1700, 1000, 1500, 2200, 1200, 1400, 2000}334 SustCaptVal := [8]float64{1500, 1700, 1000, 1500, 2200, 1200, 1400, 2000}335 PopulateAsObject(&ResultAsset, "SampleAsset", nil, 0, 0)336 for i := 1; i <= 100; i++ {337 var model ModelAssetFinancial338 model.Assets = ResultAsset[rand.Intn(len(ResultAsset))]339 YearVal = ManufacturedYearVal[rand.Intn(len(ManufacturedYearVal))]340 if YearVal == 2014 {341 Monthstring = [6]string{"07", "08", "09", "10", "11", "12"}342 } else {343 Monthstring = [6]string{"01", "02", "03", "04", "05", "06"}344 }345 dateRand = strconv.Itoa(ManufacturedYearVal[rand.Intn(len(ManufacturedYearVal))]) + "/" + Monthstring[rand.Intn(len(Monthstring))] + "/" + strconv.Itoa(CapacityVal[rand.Intn(len(CapacityVal))]) + " 00:00:00"346 model.Period, _ = fmtdate.Parse("YYYY/MM/DD hh:mm:ss", dateRand)347 model.Revenues = RevenuesVal[rand.Intn(len(RevenuesVal))]348 model.OperationalCost = OptCostVal[rand.Intn(len(OptCostVal))]349 model.MaintenanceCost = MaintCostVal[rand.Intn(len(MaintCostVal))]350 model.InsuranceCost = InsCostVal[rand.Intn(len(InsCostVal))]351 model.OtherCost = OthCostVal[rand.Intn(len(OthCostVal))]352 model.SalvageValue = SalvageVal[rand.Intn(len(SalvageVal))]353 model.AcquisitionCost = AcqCostVal[rand.Intn(len(AcqCostVal))]354 model.SustainingCapital = SustCaptVal[rand.Intn(len(SustCaptVal))]355 Save("SampleAssetFinancial", model)356 }357}358type ModelAssetMaintenanceSchedule struct {359 Assets ModelAsset360 ScheduledDate time.Time361 EstimatedMaintenanceDetail float64362 EstimatedCost float64363}364func sampleAssetMaintenanceSchedule() {365 var (366 ResultAsset []ModelAsset367 dateRand string368 )369 ManufacturedYearVal := [2]int{2015, 2014}370 Monthstring := [12]string{"01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12"}371 CapacityVal := [8]int{15, 17, 10, 15, 22, 12, 14, 20}372 EstimatedDetailVal := [8]float64{1500, 1700, 1000, 1500, 2200, 1200, 1400, 2000}373 EstimatedCostVal := [8]float64{1500, 1700, 1000, 1500, 2200, 1200, 1400, 2000}374 PopulateAsObject(&ResultAsset, "SampleAsset", nil, 0, 0)375 for i := 1; i <= 100; i++ {376 var model ModelAssetMaintenanceSchedule377 model.Assets = ResultAsset[rand.Intn(len(ResultAsset))]378 dateRand = strconv.Itoa(ManufacturedYearVal[rand.Intn(len(ManufacturedYearVal))]) + "/" + Monthstring[rand.Intn(len(Monthstring))] + "/" + strconv.Itoa(CapacityVal[rand.Intn(len(CapacityVal))]) + " 00:00:00"379 model.ScheduledDate, _ = fmtdate.Parse("YYYY/MM/DD hh:mm:ss", dateRand)380 model.EstimatedMaintenanceDetail = EstimatedDetailVal[rand.Intn(len(EstimatedDetailVal))]381 model.EstimatedCost = EstimatedCostVal[rand.Intn(len(EstimatedCostVal))]382 Save("SampleAssetMaintenanceSchedule", model)383 }384}...
Dao.go
Source:Dao.go
...10 "strings"11)12// ç»ä¸æ¨¡åæ¥å£13type Model interface {14 ToString() string15}16// 读å表ï¼æ件ï¼æ°æ®17func RfData(table string, key string, data map[string]Model) error {18 // 读å"表"æ件ï¼å
å«æ件路å¾åæ件å19 fileName := path + table + subfix20 f, ferr := os.Open(fileName)21 if ferr != nil {22 panic("读åæ件失败ãfile:" + fileName)23 }24 // 延è¿æ§è¡ï¼å
³éæ件èµæºæµ25 defer f.Close()26 // å建读åçæ件çç¼å²åº27 buf := bufio.NewReader(f)28 /* éåæ件æ°æ®29 åé符30 åï¼æ¯ä¸è¡ä»¥è±æéå·åé31 å段ï¼ç¬¬ä¸è¡ä¸ºå段32 æ°æ®ï¼é第ä¸è¡ï¼ä»¥æ¢è¡ç¬¦ä¸ºåé33 */34 field := make([]string, 0)35 rowNum := 036 for {37 row, rerr := buf.ReadBytes('\n')38 rowNum++39 fmt.Println("读å第å è¡ï¼", rowNum)40 if rerr != nil {41 if rerr == io.EOF { // ç»æè¡ãåæ件æåä¸è¡æ°æ®æ°æ®ä¹ååºæ¢è¡ï¼å¦å读åä¸å°æåä¸è¡çæ°æ®42 fmt.Println("读åæ件ç»æ符")43 break44 }45 panic("读åæ件-è¡å¤±è´¥ãfile:" + fileName)46 }47 rowData := strings.Split(strings.TrimSuffix(string(row), "\n"), ",")48 if len(field) == 0 { // 第ä¸è¡åå¨å段49 field = rowData50 fmt.Println("读åå°çå段为ï¼", field)51 } else { // é第ä¸è¡åå¨æ°æ®52 fmt.Println("读åéå段è¡çè¡æ°æ®ä¸ºï¼", rowData)53 merr := toModel(table, key, data, rowData, field)54 return merr55 }56 }57 return nil58}59/* åå¨æ°æ®å° models601. æ ¹æ® table å¾å°æ¨¡å612. å©ç¨åå°å¯¹æ¨¡åè¿è¡èµå¼623. åæ模ååå¨å°dataä¸63*/64func toModel(table string, key string, data map[string]Model, rowData []string, field []string) error {65 // 1. æ ¹æ® table å¾å°æ¨¡å66 if _, ok := sysModels[table]; !ok {67 return errors.New("éè¦åå¨ç模åä¸åå¨")68 }69 fmt.Printf("å¾å°ç模åãåæ°æ®ï¼%v, ç±»åï¼%T \n", sysModels[table], sysModels[table])70 71 // 2. å©ç¨åå°å¯¹æ¨¡åè¿è¡èµå¼72 // è·å模åçç»æä½73 arg := []reflect.Value{}74 modelValue := reflect.ValueOf(sysModels[table])75 modelStructFunc := modelValue.Call(arg) // Callæ¹æ³ä½¿ç¨è¾å
¥çåæ°inè°ç¨vææçå½æ°:func (v Value) Call(in []Value) []Value76 fmt.Printf("Reflect Call åçç±»åï¼%T ;åå¼ï¼%v, \n", modelStructFunc, modelStructFunc)77 modelFunc := modelStructFunc[0]78 fmt.Printf("Reflect Call å[0]çç±»åï¼%T ;åå¼ï¼%v, \n", modelFunc, modelFunc)79 80 var keyValue string81 for i, colDat := range rowData {82 // æ¥è¯¢å段çå¼83 if field[i] == key {84 keyValue = colDat85 }86 // è·å模åä¸å¯¹åºè®¾ç½®ç¸åºå段çæ¹æ³87 methodName := "Set" + strings.Title(field[i])88 fmt.Println("æ¼æ¥æçæ¹æ³å:"+methodName)89 90 fieldSetFunc := modelFunc.MethodByName(methodName)91 fieldSetFunc.Call([]reflect.Value{92 reflect.ValueOf(toTypeValue(modelFunc, field[i], colDat)),93 })94 95 /*getMethodName := "Get" + strings.Title(field[i])96 fieldGetFunc := modelFunc.MethodByName(getMethodName)97 getValue := fieldGetFunc.Call([]reflect.Value{})98 fmt.Printf("%s ä¹å %s ç ç±»åï¼%T;å¼ï¼%v \n", methodName, getMethodName, getValue[0], getValue[0])*/99 }100 fmt.Printf("æ¥è¯¢ç主é®ï¼%v;主é®å¼ï¼%v \n", key, keyValue)101 fmt.Printf("modelFunc.Interface() ç±»åï¼%T;å¼ï¼%v \n", modelFunc.Interface(), modelFunc.Interface())102 103 data[keyValue] = modelFunc.Interface().(Model)104 return nil105}106func toTypeValue(modelV reflect.Value, field, value string) interface{} {107 mtype := modelV.Elem().FieldByName(field).Type().Name() // [<æ¨è] // å¦å¤ä¸ç§åæ³ï¼mtype := reflect.Zero(modelV.Type().Elem()).FieldByName(field).Type().Name()108 switch mtype {109 case "int":110 b, _ := strconv.Atoi(value)111 return b112 }113 return string(value)114}115// å°æ°æ®åå
¥æ件116func fwrite(table string, userData map[string]Model) bool {117 // è·åå°è½¬åçæ°æ®å
容118 content := getModelsToString(userData)119 // æå¼æ件120 // ä¸ç®¡æ¯ Unix è¿æ¯ Windowsï¼é½éè¦ä½¿ç¨ 0666121 filePath := path+table+subfix122 outfile, outErr := os.OpenFile(filePath, os.O_WRONLY|os.O_CREATE, 0666)123 if outErr != nil {124 fmt.Println("æ件æ¾ä¸å°. file:", filePath)125 return false126 }127 defer outfile.Close()128 // å建åå
¥çç¼å²åº129 outbufwri := bufio.NewWriter(outfile)130 // åå
¥å
容131 outbufwri.WriteString(content + "\n")132 // å·æ°ç¼å²åºä¿åå
容133 outbufwri.Flush()134 135 return true136}137// æ模åæ°æ®æºè½¬å为å符串138func getModelsToString(models map[string]Model) string {139 // è®°å½å段å
容140 var fields string141 // 循ç¯å¤çæ°æ®142 var content string143 for _, model := range models {144 if fields == "" {145 // å©ç¨åå°è·åå段å
容146 rmodel := reflect.ValueOf(model)147 modelZ := rmodel.Elem() // [<æ¨è] // å¦å¤ä¸ç§åæ³ modelZ := reflect.Zero(rmodel.Type().Elem())148 // fmt.Printf("modelZ ç±»åï¼%T å¼ï¼%s", modelZ, modelZ)149 for i := 0; i < modelZ.NumField(); i++ {150 fields = fields + modelZ.Type().Field(i).Name + ","151 }152 fields = strings.TrimSuffix(fields, ",")153 }154 // è®°å½æ°æ®å
容155 content = content + model.ToString() + "\n"156 }157 // æç»å
容158 return fields + "\n" + strings.TrimSuffix(content, "\n")159}...
generator.go
Source:generator.go
...130func toLowerCamelCase(input string) string {131 return (strings.ToLower(input[:1]) + input[1:])132}133func addUnderscore(input string) string {134 return strings.Replace(strings.ToLower(underscoreRegexp.ReplaceAllString(input, `${1}_${2}`)), ".", "_", -1)135}136func stripVersion(input string) string {137 return versionRegex.ReplaceAllString(input, "")138}139func capitalize(s string) string {140 if len(s) <= 1 {141 return strings.ToUpper(s)142 }143 return strings.ToUpper(s[:1]) + s[1:]144}...
String
Using AI Code Generation
1import "fmt"2type Person struct {3}4func (p Person) String() string {5 return fmt.Sprintf("%v (%v years)", p.name, p.age)6}7func main() {8 a := Person{"Arthur Dent", 42}9 z := Person{"Zaphod Beeblebrox", 9001}10 fmt.Println(a, z)11}12Arthur Dent (42 years) Zaphod Beeblebrox (9001 years)13import "fmt"14func main() {15 if ans != 0 {16 fmt.Println("No error")17 }18}19panic(0x4000c0, 0x4200b0)20main.main()21runtime.goexit()
String
Using AI Code Generation
1import (2func init() {3 orm.RegisterDataBase("default", "mysql", "root:@/test?charset=utf8", 30)4 orm.RegisterModel(new(User))5 orm.RunSyncdb("default", false, true)6}7func main() {8 o := orm.NewOrm()9 user := User{Id: 1}10 err := o.Read(&user)11 if err == orm.ErrNoRows {12 fmt.Println("No result found.")13 } else if err == orm.ErrMissPK {14 fmt.Println("No primary key found.")15 } else {16 fmt.Println(user.Id, user.Name)17 }18}19type User struct {20 Name string `orm:"size(100)"`21}
String
Using AI Code Generation
1fmt.Println("String method of model class: ", model.String())2fmt.Println("String method of model class: ", model)3fmt.Println("String method of model class: ", model.String())4fmt.Println("String method of model class: ", model)5fmt.Println("String method of model class: ", model.String())6fmt.Println("String method of model class: ", model)7fmt.Println("String method of model class: ", model.String())8fmt.Println("String method of model class: ", model)9fmt.Println("String method of model class: ", model.String())10fmt.Println("String method of model class: ", model)11fmt.Println("String method of model class: ", model.String())12fmt.Println("String method of model class: ", model)13fmt.Println("String method of model class: ", model.String())14fmt.Println("String method of model class: ", model)15fmt.Println("String method of model class: ", model.String())16fmt.Println("String method of model class: ", model)17fmt.Println("String method of model class: ", model.String())18fmt.Println("String method of model class: ", model)19fmt.Println("String method of model class: ", model.String())20fmt.Println("String method of model
String
Using AI Code Generation
1import (2func main() {3 var s1 = Student{1, "John", 23}4 fmt.Println(s1)5}6{1 John 23}7{1 John 23}
String
Using AI Code Generation
1import (2func main() {3 fmt.Println(c.String())4}5import "fmt"6type Customer struct {7}8func (c Customer) String() string {9 return fmt.Sprintf("%s is %d years old", c.Name, c.Age)10}11import (12func main() {13 fmt.Println(c.String())14 fmt.Println(c.StringWithPointerReceiver())15}16import "fmt"17type Customer struct {18}19func (c Customer) String() string {20 return fmt.Sprintf("%s is %d years old", c.Name, c.Age)21}22func (c *Customer) StringWithPointerReceiver() string {23 return fmt.Sprintf("%s is %d years old", c.Name, c.Age)24}
String
Using AI Code Generation
1import (2func main() {3 fmt.Println(a)4}5{Rajesh 28}6import (7func main() {8 fmt.Println(a.String())9}10{Rajesh 28}
String
Using AI Code Generation
1import (2func main() {3m := model.Model{1, "John"}4fmt.Println(m)5}6Model{1,John}
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!