How to use remain method of json Package

Best Go-testdeep code snippet using json.remain

DashBoardLib.go

Source:DashBoardLib.go Github

copy

Full Screen

...520 }521 }522 }523 var ReturnJsonAPP JsonResult524 var oldappremain int525 for key, _ := range APPWeekDateReaminResult {526 if APPWeekDateReaminResult[key].RemainCounter != 0 {527 oldappremain = APPWeekDateReaminResult[key].RemainCounter528 }529 ReturnJsonAPP.Name = append(ReturnJsonAPP.Name, APPWeekDateReaminResult[key].Name)530 if APPWeekDateReaminResult[key].RemainCounter == 0 {531 ReturnJsonAPP.RemainCounter = append(ReturnJsonAPP.RemainCounter, oldappremain)532 } else {533 oldappremain = APPWeekDateReaminResult[key].RemainCounter534 ReturnJsonAPP.RemainCounter = append(ReturnJsonAPP.RemainCounter, APPWeekDateReaminResult[key].RemainCounter)535 }536 }537 return ReturnJsonAPP538}539func TYGHDiffWeekDate(ProjectName string, YearWeek string) []JsonResult {540 db, err := sql.Open("mysql", "eli:eli@/Jira_Data")541 // specific week data542 var APPWeekDateReaminResult []JiraIssuesDateRemain543 var WEBWeekDateReaminResult []JiraIssuesDateRemain544 s := strings.Split(YearWeek, "-")545 sisoYear, sisoWeek := s[0], s[1]546 isoYear, _ := strconv.Atoi(sisoYear)547 isoWeek, _ := strconv.Atoi(sisoWeek)548 tmpWeekFullName := WeekWorkDayArray(isoYear, isoWeek)549 for _, value := range tmpWeekFullName {550 var DateRemain JiraIssuesDateRemain551 DateRemain.Name = value552 APPWeekDateReaminResult = append(APPWeekDateReaminResult, DateRemain)553 WEBWeekDateReaminResult = append(WEBWeekDateReaminResult, DateRemain)554 }555 //Get All data556 var APPDateReaminResult []JiraIssuesDateRemain557 var WEBDateReaminResult []JiraIssuesDateRemain558 DateRemainCreateSQL := "SELECT * from (select date(UpdatedTime) as date from Issues WHERE `Key` LIKE '" + ProjectName + "-%' union " +559 "select date(CreatedTime) as date from Issues WHERE `Key` LIKE '" + ProjectName + "-%' ) as a GROUP by a.date"560 CreateDateRemains, err := db.Query(DateRemainCreateSQL)561 checkerr(DateRemainCreateSQL, err)562 for CreateDateRemains.Next() {563 var (564 DateRemain JiraIssuesDateRemain565 tmpCreateDate string566 )567 CreateDateRemains.Scan(&tmpCreateDate)568 if tmpCreateDate != "0000-00-00" {569 DateRemain.Name = tmpCreateDate570 APPDateReaminResult = append(APPDateReaminResult, DateRemain)571 WEBDateReaminResult = append(WEBDateReaminResult, DateRemain)572 }573 }574 CreateDateRemains.Close()575 CreateIssueSQL := "SELECT Id,Version,DATE(CreatedTime) as createdate FROM `Issues` WHERE `Key` like '" + ProjectName + "-%' ORDER BY `Issues`.`Version` ASC"576 Issuess, err := db.Query(CreateIssueSQL)577 checkerr(CreateIssueSQL, err)578 for Issuess.Next() {579 var (580 tmpId string581 tmpVerId string582 tmpDate string583 )584 Issuess.Scan(&tmpId, &tmpVerId, &tmpDate)585 VersionsSQL := "SELECT `Versions`.`Name` FROM `Versions` INNER join `Version` on `Versions`.`Sn` = `Version`.`Data` AND `Version`.`Enable`='1' WHERE `Version`.`Id`='" + tmpId + "'"586 // VersionsSQL := "SELECT Data FROM `Version` WHERE Id='" + tmpId + "' AND Enable='1'"587 VersionsROW, err := db.Query(VersionsSQL)588 checkerr(VersionsSQL, err)589 CreateVersionCounter := 0590 for VersionsROW.Next() {591 CreateVersionCounter++592 var VersionName string593 VersionsROW.Scan(&VersionName)594 if strings.Contains(VersionName, "APP") {595 for Key, Value := range APPDateReaminResult {596 if Value.Name == tmpDate {597 APPDateReaminResult[Key].CreateCounter++598 }599 }600 } else if strings.Contains(VersionName, "WEB") {601 for Key, Value := range WEBDateReaminResult {602 if Value.Name == tmpDate {603 WEBDateReaminResult[Key].CreateCounter++604 }605 }606 }607 }608 VersionsROW.Close()609 // log.Println(CreateVersionCounter)610 ResolvedIssueSQL := "SELECT Status as createdate FROM `Issues` WHERE `Key` like '" + ProjectName + "-%' AND Id='" + tmpId + "' ORDER BY `Issues`.`Version` ASC"611 Status := QuerySingle(ResolvedIssueSQL)612 if Status == "Closed" {613 HistorySQL := "SELECT date(Created) FROM `Historys` WHERE `Jid` = '" + tmpId + "' AND Tostring='Resolved' ORDER BY Sn DESC LIMIT 1"614 ResolveDate := QuerySingle(HistorySQL)615 if ResolveDate == "" {616 HistorySQL := "SELECT date(Created) FROM `Historys` WHERE `Jid` = '" + tmpId + "' AND Tostring='Closed' ORDER BY Sn DESC LIMIT 1"617 ResolveDate = QuerySingle(HistorySQL)618 }619 FixVersionsSQL := "SELECT `Fixversions`.`Name` FROM `Fixversions` INNER join `Fixversion` on `Fixversions`.`Sn` = `Fixversion`.`Data` AND `Fixversion`.`Enable`='1' WHERE `Fixversion`.`Id`='" + tmpId + "'"620 FixVersionsROW, err := db.Query(FixVersionsSQL)621 checkerr(FixVersionsSQL, err)622 for FixVersionsROW.Next() {623 var FixVersionName string624 FixVersionsROW.Scan(&FixVersionName)625 if strings.Contains(FixVersionName, "APP") && CreateVersionCounter >= 0 {626 for Key, Value := range APPDateReaminResult {627 if Value.Name == ResolveDate {628 APPDateReaminResult[Key].CloseCounter++629 }630 }631 } else if strings.Contains(FixVersionName, "WEB") && CreateVersionCounter >= 0 {632 for Key, Value := range WEBDateReaminResult {633 if Value.Name == ResolveDate {634 WEBDateReaminResult[Key].CloseCounter++635 }636 }637 }638 CreateVersionCounter--639 }640 FixVersionsROW.Close()641 }642 }643 Issuess.Close()644 db.Close()645 WEBRemain := 0646 APPRemain := 0647 lastWebRemain := 0648 lastAPPRemain := 0649 for key, _ := range WEBDateReaminResult {650 WEBRemain = (WEBRemain + WEBDateReaminResult[key].CreateCounter) - WEBDateReaminResult[key].CloseCounter651 WEBDateReaminResult[key].RemainCounter = WEBRemain652 for Key, _ := range WEBWeekDateReaminResult {653 if WEBWeekDateReaminResult[Key].Name == WEBDateReaminResult[key].Name {654 WEBWeekDateReaminResult[Key].RemainCounter = WEBRemain655 if lastWebRemain == 0 {656 lastWebRemain = WEBDateReaminResult[key-1].RemainCounter657 }658 }659 }660 APPRemain = (APPRemain + APPDateReaminResult[key].CreateCounter) - APPDateReaminResult[key].CloseCounter661 APPDateReaminResult[key].RemainCounter = APPRemain662 for Key, _ := range APPWeekDateReaminResult {663 if APPWeekDateReaminResult[Key].Name == APPDateReaminResult[key].Name {664 APPWeekDateReaminResult[Key].RemainCounter = APPRemain665 if lastAPPRemain == 0 {666 lastAPPRemain = APPDateReaminResult[key-1].RemainCounter667 }668 }669 }670 }671 // log.Println(lastAPPRemain, lastWebRemain)672 var ReturnJsonAPP JsonResult673 var ReturnJsonWEB JsonResult674 var oldwebremain, oldappremain int675 for key, _ := range WEBWeekDateReaminResult {676 ReturnJsonWEB.Name = append(ReturnJsonWEB.Name, WEBWeekDateReaminResult[key].Name)677 if WEBWeekDateReaminResult[key].RemainCounter != 0 {678 oldwebremain = WEBWeekDateReaminResult[key].RemainCounter679 lastWebRemain = oldwebremain680 } else {681 WEBWeekDateReaminResult[key].RemainCounter = lastWebRemain682 }683 if APPWeekDateReaminResult[key].RemainCounter != 0 {684 oldappremain = APPWeekDateReaminResult[key].RemainCounter685 lastAPPRemain = oldappremain686 } else {687 APPWeekDateReaminResult[key].RemainCounter = lastAPPRemain688 }689 // log.Println(...)690 // oldwebremain = WEBWeekDateReaminResult[key].RemainCounter691 ReturnJsonWEB.RemainCounter = append(ReturnJsonWEB.RemainCounter, WEBWeekDateReaminResult[key].RemainCounter)692 ReturnJsonAPP.Name = append(ReturnJsonAPP.Name, APPWeekDateReaminResult[key].Name)693 // oldappremain = APPWeekDateReaminResult[key].RemainCounter694 ReturnJsonAPP.RemainCounter = append(ReturnJsonAPP.RemainCounter, APPWeekDateReaminResult[key].RemainCounter)695 }696 // var ReturnJsonAPP JsonResult697 // var ReturnJsonWEB JsonResult698 // var oldwebremain, oldappremain int699 // for key, _ := range WEBWeekDateReaminResult {700 // ReturnJsonWEB.Name = append(ReturnJsonWEB.Name, WEBWeekDateReaminResult[key].Name)701 // if WEBWeekDateReaminResult[key].RemainCounter != 0 {702 // oldwebremain = WEBWeekDateReaminResult[key].RemainCounter703 // }704 // if APPWeekDateReaminResult[key].RemainCounter != 0 {705 // oldappremain = APPWeekDateReaminResult[key].RemainCounter706 // }707 // // log.Println(key, oldappremain, oldwebremain)708 // if WEBWeekDateReaminResult[key].RemainCounter == 0 {709 // ReturnJsonWEB.RemainCounter = append(ReturnJsonWEB.RemainCounter, oldwebremain)710 // } else {711 // oldwebremain = WEBWeekDateReaminResult[key].RemainCounter712 // ReturnJsonWEB.RemainCounter = append(ReturnJsonWEB.RemainCounter, WEBWeekDateReaminResult[key].RemainCounter)713 // }714 // ReturnJsonAPP.Name = append(ReturnJsonAPP.Name, APPWeekDateReaminResult[key].Name)715 // if APPWeekDateReaminResult[key].RemainCounter == 0 {716 // ReturnJsonAPP.RemainCounter = append(ReturnJsonAPP.RemainCounter, oldappremain)717 // } else {718 // oldappremain = APPWeekDateReaminResult[key].RemainCounter719 // ReturnJsonAPP.RemainCounter = append(ReturnJsonAPP.RemainCounter, APPWeekDateReaminResult[key].RemainCounter)720 // }721 // // log.Println(key, oldappremain, oldwebremain)722 // }723 var ReturnResult []JsonResult724 ReturnResult = append(ReturnResult, ReturnJsonAPP, ReturnJsonWEB)725 return ReturnResult726}727func TYGHDiffDate(ProjectName string) ([]JiraIssuesDateRemain, []JiraIssuesDateRemain) {728 db, err := sql.Open("mysql", "eli:eli@/Jira_Data")729 // Date Create730 // start := time.Now()731 DateRemainCreateSQL := "SELECT * from (select date(UpdatedTime) as date from Issues WHERE `Key` LIKE 'TYGH-%' " +732 " union " +733 " select date(CreatedTime) as date from Issues WHERE `Key` LIKE 'TYGH-%' ) as a GROUP by a.date "734 CreateDateRemains, err := db.Query(DateRemainCreateSQL)735 checkerr(DateRemainCreateSQL, err)736 var APPDateReaminResult []JiraIssuesDateRemain737 var WEBDateReaminResult []JiraIssuesDateRemain738 for CreateDateRemains.Next() {739 var (740 DateRemain JiraIssuesDateRemain741 tmpCreateDate string742 )743 CreateDateRemains.Scan(&tmpCreateDate)744 if tmpCreateDate != "0000-00-00" {745 DateRemain.Name = tmpCreateDate746 APPDateReaminResult = append(APPDateReaminResult, DateRemain)747 WEBDateReaminResult = append(WEBDateReaminResult, DateRemain)748 }749 }750 CreateDateRemains.Close()751 CreateIssueSQL := "SELECT Id,Version,DATE(CreatedTime) as createdate FROM `Issues` WHERE `Key` like '" + ProjectName + "-%' ORDER BY `Issues`.`Version` ASC"752 Issuess, err := db.Query(CreateIssueSQL)753 checkerr(CreateIssueSQL, err)754 for Issuess.Next() {755 var (756 tmpId string757 tmpVerId string758 tmpDate string759 )760 Issuess.Scan(&tmpId, &tmpVerId, &tmpDate)761 VersionsSQL := "SELECT `Versions`.`Name` FROM `Versions` INNER join `Version` on `Versions`.`Sn` = `Version`.`Data` AND `Version`.`Enable`='1' WHERE `Version`.`Id`='" + tmpId + "'"762 // VersionsSQL := "SELECT Data FROM `Version` WHERE Id='" + tmpId + "' AND Enable='1'"763 VersionsROW, err := db.Query(VersionsSQL)764 checkerr(VersionsSQL, err)765 CreateVersionCounter := 0766 for VersionsROW.Next() {767 CreateVersionCounter++768 var VersionName string769 VersionsROW.Scan(&VersionName)770 if strings.Contains(VersionName, "APP") {771 for Key, Value := range APPDateReaminResult {772 if Value.Name == tmpDate {773 APPDateReaminResult[Key].CreateCounter++774 }775 }776 } else if strings.Contains(VersionName, "WEB") {777 for Key, Value := range WEBDateReaminResult {778 if Value.Name == tmpDate {779 WEBDateReaminResult[Key].CreateCounter++780 }781 }782 }783 }784 VersionsROW.Close()785 // log.Println(CreateVersionCounter)786 ResolvedIssueSQL := "SELECT Status as createdate FROM `Issues` WHERE `Key` like '" + ProjectName + "-%' AND Id='" + tmpId + "' ORDER BY `Issues`.`Version` ASC"787 Status := QuerySingle(ResolvedIssueSQL)788 if Status == "Closed" {789 HistorySQL := "SELECT date(Created) FROM `Historys` WHERE `Jid` = '" + tmpId + "' AND Tostring='Resolved' ORDER BY Sn DESC LIMIT 1"790 ResolveDate := QuerySingle(HistorySQL)791 if ResolveDate == "" {792 HistorySQL := "SELECT date(Created) FROM `Historys` WHERE `Jid` = '" + tmpId + "' AND Tostring='Closed' ORDER BY Sn DESC LIMIT 1"793 ResolveDate = QuerySingle(HistorySQL)794 }795 FixVersionsSQL := "SELECT `Fixversions`.`Name` FROM `Fixversions` INNER join `Fixversion` on `Fixversions`.`Sn` = `Fixversion`.`Data` AND `Fixversion`.`Enable`='1' WHERE `Fixversion`.`Id`='" + tmpId + "'"796 // FixVersionsSQL := "SELECT Data FROM `Fixversion` WHERE Id='" + tmpId + "' AND Enable='1'"797 // log.Println("tmpid", tmpId)798 FixVersionsROW, err := db.Query(FixVersionsSQL)799 checkerr(FixVersionsSQL, err)800 for FixVersionsROW.Next() {801 var FixVersionName string802 FixVersionsROW.Scan(&FixVersionName)803 if strings.Contains(FixVersionName, "APP") && CreateVersionCounter >= 0 {804 for Key, Value := range APPDateReaminResult {805 if Value.Name == ResolveDate {806 APPDateReaminResult[Key].CloseCounter++807 }808 }809 } else if strings.Contains(FixVersionName, "WEB") && CreateVersionCounter >= 0 {810 // log.Println(ProjectName, "WEB Create", VersionName, tmpId, tmpDate, webappendflag)811 for Key, Value := range WEBDateReaminResult {812 if Value.Name == ResolveDate {813 WEBDateReaminResult[Key].CloseCounter++814 }815 }816 }817 CreateVersionCounter--818 }819 FixVersionsROW.Close()820 }821 }822 Issuess.Close()823 db.Close()824 // sortutil.AscByField(APPDateReaminResult, "Name")825 // sortutil.AscByField(WEBDateReaminResult, "Name")826 WEBRemain := 0827 APPRemain := 0828 for key, _ := range WEBDateReaminResult {829 WEBRemain = (WEBRemain + WEBDateReaminResult[key].CreateCounter) - WEBDateReaminResult[key].CloseCounter830 WEBDateReaminResult[key].RemainCounter = WEBRemain831 APPRemain = (APPRemain + APPDateReaminResult[key].CreateCounter) - APPDateReaminResult[key].CloseCounter832 APPDateReaminResult[key].RemainCounter = APPRemain833 }834 var ReturnJsonAPP JsonResult835 var ReturnJsonWEB JsonResult836 for key, _ := range WEBDateReaminResult {837 ReturnJsonWEB.Name = append(ReturnJsonWEB.Name, WEBDateReaminResult[key].Name)838 // ReturnJsonWEB.CreateCounter = append(ReturnJsonWEB.CreateCounter, WEBDateReaminResult[key].CreateCounter)839 // ReturnJsonWEB.CloseCounter = append(ReturnJsonWEB.CloseCounter, WEBDateReaminResult[key].CloseCounter)840 ReturnJsonWEB.RemainCounter = append(ReturnJsonWEB.RemainCounter, WEBDateReaminResult[key].RemainCounter)841 ReturnJsonAPP.Name = append(ReturnJsonAPP.Name, APPDateReaminResult[key].Name)842 // ReturnJsonAPP.CreateCounter = append(ReturnJsonAPP.CreateCounter, APPDateReaminResult[key].CreateCounter)843 // ReturnJsonAPP.CloseCounter = append(ReturnJsonAPP.CloseCounter, APPDateReaminResult[key].CloseCounter)844 ReturnJsonAPP.RemainCounter = append(ReturnJsonAPP.RemainCounter, APPDateReaminResult[key].RemainCounter)845 }846 // log.Println(ReturnJsonAPP, ReturnJsonWEB)847 // elapsed := time.Since(start)848 // log.Println(elapsed)849 // return ReturnJsonAPP, ReturnJsonWEB850 // var ReturnResult []JsonResult851 // ReturnResult = append(ReturnResult, ReturnJsonAPP, ReturnJsonWEB)852 // return ReturnResult853 return APPDateReaminResult, WEBDateReaminResult854}855func TYGHDiffWeek(ProjectName string) []JsonResult {856 db, _ := sql.Open("mysql", "eli:eli@/Jira_Data")857 APPDateReaminResult, WEBDateReaminResult := TYGHDiffDate(ProjectName)858 DateRemainCreateSQL := "SELECT CONCAT(yeardate ,'-' ,date ) as yearweek from (select UpdatedTime,YEAR(UpdatedTime) as yeardate,WEEKOFYEAR(UpdatedTime) as date from Issues WHERE `UpdatedTime`!='0000-00-00' AND `Key` LIKE 'TYGH-%' " +859 " union " +860 " select UpdatedTime,YEAR(UpdatedTime) as yeardate ,WEEKOFYEAR(CreatedTime) as date from Issues WHERE `UpdatedTime`!='0000-00-00' AND `Key` LIKE 'TYGH-%' ) as a GROUP by a.date order by UpdatedTime "861 CreateDateRemains, err := db.Query(DateRemainCreateSQL)862 checkerr(DateRemainCreateSQL, err)863 var APPWeekReaminResult []JiraIssuesDateRemain864 var WEBWeekReaminResult []JiraIssuesDateRemain865 for CreateDateRemains.Next() {866 var (867 DateRemain JiraIssuesDateRemain868 tmpCreateDate string869 )870 CreateDateRemains.Scan(&tmpCreateDate)871 if tmpCreateDate != "" {872 DateRemain.Name = tmpCreateDate873 APPWeekReaminResult = append(APPWeekReaminResult, DateRemain)874 WEBWeekReaminResult = append(WEBWeekReaminResult, DateRemain)875 }876 }877 CreateDateRemains.Close()878 db.Close()879 layout := "2006-01-02"880 for key, value := range APPDateReaminResult {881 t, err := time.Parse(layout, value.Name)882 if err != nil {883 log.Println(err)884 }885 isoYear, isoWeek := t.ISOWeek()886 // log.Println(isoWeek, value.Name)887 sisoWeek := strconv.Itoa(isoWeek)888 sisoYear := strconv.Itoa(isoYear)889 yearweekStr := sisoYear + "-" + sisoWeek890 for index, weeknumber := range APPWeekReaminResult {891 if weeknumber.Name == yearweekStr {892 APPWeekReaminResult[index].CreateCounter += APPDateReaminResult[key].CreateCounter893 APPWeekReaminResult[index].CloseCounter += APPDateReaminResult[key].CloseCounter894 WEBWeekReaminResult[index].CreateCounter += WEBDateReaminResult[key].CreateCounter895 WEBWeekReaminResult[index].CloseCounter += WEBDateReaminResult[key].CloseCounter896 }897 }898 }899 WEBRemain := 0900 APPRemain := 0901 for key, _ := range WEBWeekReaminResult {902 WEBRemain = (WEBRemain + WEBWeekReaminResult[key].CreateCounter) - WEBWeekReaminResult[key].CloseCounter903 WEBWeekReaminResult[key].RemainCounter = WEBRemain904 APPRemain = (APPRemain + APPWeekReaminResult[key].CreateCounter) - APPWeekReaminResult[key].CloseCounter905 APPWeekReaminResult[key].RemainCounter = APPRemain906 }907 now := time.Now()908 year, week := now.ISOWeek()909 todayisoWeek := strconv.Itoa(week)910 todayisoYear := strconv.Itoa(year)911 todayyearweekStr := todayisoYear + "-" + todayisoWeek912 var ReturnJsonAPP JsonResult913 var ReturnJsonWEB JsonResult914 for key, _ := range WEBWeekReaminResult {915 if WEBWeekReaminResult[key].Name != todayyearweekStr {916 ReturnJsonWEB.Name = append(ReturnJsonWEB.Name, WEBWeekReaminResult[key].Name)917 ReturnJsonWEB.RemainCounter = append(ReturnJsonWEB.RemainCounter, WEBWeekReaminResult[key].RemainCounter)918 ReturnJsonAPP.Name = append(ReturnJsonAPP.Name, APPWeekReaminResult[key].Name)919 ReturnJsonAPP.RemainCounter = append(ReturnJsonAPP.RemainCounter, APPWeekReaminResult[key].RemainCounter)920 }921 }922 var ReturnResult []JsonResult923 ReturnResult = append(ReturnResult, ReturnJsonAPP, ReturnJsonWEB)924 return ReturnResult925}926func PieChart(ProjectName string, TYPE string) JsonResultPie {927 db, err := sql.Open("mysql", "eli:eli@/Jira_Data")928 var ReturnJson JsonResult929 var ReturnJsonPie JsonResultPie930 PrioritySQL := "Select `" + TYPE + "` FROM `Issues` WHERE `Key` like '" + ProjectName + "-%' group by `" + TYPE + "` "931 // log.Println(PrioritySQL)932 PriorityRows, err := db.Query(PrioritySQL)933 checkerr(PrioritySQL, err)934 for PriorityRows.Next() {935 var (936 tmpName string937 )938 PriorityRows.Scan(&tmpName)939 // log.Println(tmpName)940 if tmpName != "" {941 ReturnJson.Name = append(ReturnJson.Name, tmpName)942 ReturnJsonPie.Name = append(ReturnJsonPie.Name, tmpName)943 } else if tmpName == "" && TYPE == "Resolution" {944 ReturnJson.Name = append(ReturnJson.Name, tmpName)945 ReturnJsonPie.Name = append(ReturnJsonPie.Name, "Unresolved")946 }947 }948 PriorityRows.Close()949 totalcounter := 0950 for _, Value := range ReturnJson.Name {951 // log.Println(key, Value)952 tmpValue := Value953 TmpCounter := 0954 SQL := "Select count(*) FROM `Issues` WHERE `Key` like '" + ProjectName + "-%' AND `" + TYPE + "` = ? "955 // log.Println(SQL, "="+tmpValue+"=")956 rows, err := db.Query(SQL, tmpValue)957 if err != nil {958 log.Fatal(err)959 }960 defer rows.Close()961 for rows.Next() {962 err := rows.Scan(&TmpCounter)963 if err != nil {964 log.Fatal(err)965 }966 // log.Println(TmpCounter)967 }968 rows.Close()969 ReturnJson.CreateCounter = append(ReturnJson.CreateCounter, TmpCounter)970 totalcounter = totalcounter + TmpCounter971 }972 for key, _ := range ReturnJson.Name {973 tmpremain := ((float64)(ReturnJson.CreateCounter[key]) * 100) / (float64)(totalcounter)974 // log.Println(tmpremain, ReturnJson.CreateCounter[key], totalcounter)975 ReturnJsonPie.RemainCounter = append(ReturnJsonPie.RemainCounter, tmpremain)976 }977 // log.Println(ReturnJsonPie)978 db.Close()979 // // log.Println(ReturnJson)980 return ReturnJsonPie981}982func IssueTimespent(ProjectName string) []JsonResultTable {983 db, err := sql.Open("mysql", "eli:eli@/Jira_Data")984 RemainIssueSQL := "SELECT a.`Key`, a.`Summary`, a.`Priority`, a.DiffDate, a.`Assignee` from (SELECT *,DATEDIFF(DATE(`UpdatedTime`),DATE(CURDATE() )) AS DiffDate " +985 "FROM `Issues` WHERE `Key` LIKE '" + ProjectName + "-%' AND Status!='Closed' AND Resolution not like '% Fix' ORDER BY UpdatedTime AND Status='Closed' )as a " +986 "ORDER by a.DiffDate"987 RemainIssues, err := db.Query(RemainIssueSQL)988 checkerr(RemainIssueSQL, err)989 var RemainIssueResult []JsonResultTable990 for RemainIssues.Next() {991 var tmpRemainIssue JsonResultTable992 RemainIssues.Scan(&tmpRemainIssue.Name, &tmpRemainIssue.Summary, &tmpRemainIssue.Priority, &tmpRemainIssue.DiffDate, &tmpRemainIssue.Assignee)993 // log.Println(tmpRemainIssue)994 RemainIssueResult = append(RemainIssueResult, tmpRemainIssue)995 }996 RemainIssues.Close()997 db.Close()998 return RemainIssueResult999}1000func LastUpdateWeek() JsonResultTime {1001 db, err := sql.Open("mysql", "eli:eli@/Jira_Data")1002 RemainIssueSQL := "SELECT week(FROM_UNIXTIME(UNIX_TIMESTAMP(MAX(UPDATE_TIME)))) as week , FROM_UNIXTIME(UNIX_TIMESTAMP(MAX(UPDATE_TIME))) as last_update , NOW() as now " +1003 "FROM information_schema.tables WHERE TABLE_SCHEMA='Jira_Data' GROUP BY TABLE_SCHEMA"1004 RemainIssues, err := db.Query(RemainIssueSQL)1005 checkerr(RemainIssueSQL, err)1006 var returnJson JsonResultTime1007 for RemainIssues.Next() {1008 RemainIssues.Scan(&returnJson.Week, &returnJson.LastUpdate, &returnJson.Current)1009 }1010 RemainIssues.Close()1011 db.Close()1012 // log.Println(returnJson)1013 return returnJson1014}1015func DueDateRemain(ProjectName string) []JsonResultTable {1016 //SELECT * FROM `Issues` WHERE `DueDate`!= "0000-00-00" AND Status != 'Closed' AND `Key` like 'BABY-%' ORDER BY `FixVersions` DESC1017 db, err := sql.Open("mysql", "eli:eli@/Jira_Data")1018 RemainIssueSQL := "SELECT `Key`, `Summary`, `Priority`, `Assignee` FROM `Issues` WHERE `DueDate`!= '0000-00-00' AND Status != 'Closed' AND `Key` like '" + ProjectName + "-%' ORDER BY `FixVersions` DESC"1019 RemainIssues, err := db.Query(RemainIssueSQL)1020 checkerr(RemainIssueSQL, err)1021 var RemainIssueResult []JsonResultTable1022 for RemainIssues.Next() {1023 var tmpRemainIssue JsonResultTable1024 RemainIssues.Scan(&tmpRemainIssue.Name, &tmpRemainIssue.Summary, &tmpRemainIssue.Priority, &tmpRemainIssue.Assignee)1025 // log.Println(tmpRemainIssue)1026 RemainIssueResult = append(RemainIssueResult, tmpRemainIssue)1027 }1028 RemainIssues.Close()1029 db.Close()1030 return RemainIssueResult1031}1032func BABYIOSPieChart(ProjectName string, TYPE string) JsonResultPie {1033 db, err := sql.Open("mysql", "eli:eli@/Jira_Data")1034 var ReturnJson JsonResult1035 var ReturnJsonPie JsonResultPie1036 PrioritySQL := "Select `" + TYPE + "` FROM `Issues` WHERE `Reporter`='Ming_Chiang' AND `Key` like '" + ProjectName + "-%' group by `" + TYPE + "` "1037 // log.Println(PrioritySQL)1038 PriorityRows, err := db.Query(PrioritySQL)1039 checkerr(PrioritySQL, err)1040 for PriorityRows.Next() {1041 var (1042 tmpName string1043 )1044 PriorityRows.Scan(&tmpName)1045 // log.Println(tmpName)1046 if tmpName != "" {1047 ReturnJson.Name = append(ReturnJson.Name, tmpName)1048 ReturnJsonPie.Name = append(ReturnJsonPie.Name, tmpName)1049 } else if tmpName == "" && TYPE == "Resolution" {1050 ReturnJson.Name = append(ReturnJson.Name, tmpName)1051 ReturnJsonPie.Name = append(ReturnJsonPie.Name, "Unresolved")1052 }1053 }1054 PriorityRows.Close()1055 totalcounter := 01056 for _, Value := range ReturnJson.Name {1057 // log.Println(key, Value)1058 tmpValue := Value1059 TmpCounter := 01060 SQL := "Select count(*) FROM `Issues` WHERE `Reporter`='Ming_Chiang' AND `Key` like '" + ProjectName + "-%' AND `" + TYPE + "` = ? "1061 // log.Println(SQL, "="+tmpValue+"=")1062 rows, err := db.Query(SQL, tmpValue)1063 if err != nil {1064 log.Fatal(err)1065 }1066 defer rows.Close()1067 for rows.Next() {1068 err := rows.Scan(&TmpCounter)1069 if err != nil {1070 log.Fatal(err)1071 }1072 // log.Println(TmpCounter)1073 }1074 rows.Close()1075 ReturnJson.CreateCounter = append(ReturnJson.CreateCounter, TmpCounter)1076 totalcounter = totalcounter + TmpCounter1077 }1078 for key, _ := range ReturnJson.Name {1079 tmpremain := ((float64)(ReturnJson.CreateCounter[key]) * 100) / (float64)(totalcounter)1080 // log.Println(tmpremain, ReturnJson.CreateCounter[key], totalcounter)1081 ReturnJsonPie.RemainCounter = append(ReturnJsonPie.RemainCounter, tmpremain)1082 }1083 // log.Println(ReturnJsonPie)1084 db.Close()1085 // // log.Println(ReturnJson)1086 return ReturnJsonPie1087}1088func BABYIOSIssueTimespent(ProjectName string) []JsonResultTable {1089 db, err := sql.Open("mysql", "eli:eli@/Jira_Data")1090 RemainIssueSQL := "SELECT a.`Key`, a.`Summary`, a.`Priority`, a.DiffDate, a.`Assignee` from (SELECT *,DATEDIFF(DATE(`UpdatedTime`),DATE(CURDATE() )) AS DiffDate " +1091 "FROM `Issues` WHERE `Reporter`='Ming_Chiang' AND `Key` LIKE '" + ProjectName + "-%' AND Status!='Done' AND Resolution not like '% Fix' ORDER BY UpdatedTime AND Status='Closed' )as a " +1092 "ORDER by a.DiffDate"1093 RemainIssues, err := db.Query(RemainIssueSQL)1094 checkerr(RemainIssueSQL, err)1095 var RemainIssueResult []JsonResultTable1096 for RemainIssues.Next() {1097 var tmpRemainIssue JsonResultTable1098 RemainIssues.Scan(&tmpRemainIssue.Name, &tmpRemainIssue.Summary, &tmpRemainIssue.Priority, &tmpRemainIssue.DiffDate, &tmpRemainIssue.Assignee)1099 // log.Println(tmpRemainIssue)1100 RemainIssueResult = append(RemainIssueResult, tmpRemainIssue)1101 }1102 RemainIssues.Close()1103 db.Close()1104 return RemainIssueResult1105}1106func BABYIOSVersionData(ProjectName string) []JiraIssuesStatusDiffVersion {1107 db, err := sql.Open("mysql", "eli:eli@/Jira_Data")1108 // ProjectName := "TYGH"1109 versSQL := "SELECT Id,Name from ( " +1110 "SELECT f.Id,f.Name,f.Project FROM Fixversions as f LEFT join Versions as v on f.Id = v.Id UNION DISTINCT " +1111 "SELECT v.Id,v.Name,v.Project FROM Fixversions as f RIGHT join Versions as v on f.Id = v.Id) as a where Project='" + ProjectName + "' group by a.Id " +1112 "ORDER BY `a`.`Id` ASC"1113 Vers, err := db.Query(versSQL)1114 checkerr(versSQL, err)1115 var DiffVersionResult []JiraIssuesStatusDiffVersion1116 for Vers.Next() {1117 var (1118 IssueVersions JiraIssuesStatusDiffVersion1119 tmpVerId string1120 tmpVerName string1121 )1122 Vers.Scan(&tmpVerId, &tmpVerName)1123 IssueVersions.Name = tmpVerName1124 DiffVersionResult = append(DiffVersionResult, IssueVersions)1125 }1126 Vers.Close()1127 // // TODO no version1128 sortutil.AscByField(DiffVersionResult, "Name")1129 IssuesSQL := "SELECT Id,FixVersions,Status,Version FROM Issues WHERE `Reporter`='Ming_Chiang' AND `Key` like '" + ProjectName + "-%' AND Resolution not like '% Fix'"1130 Issuess, err := db.Query(IssuesSQL)1131 checkerr(IssuesSQL, err)1132 for Issuess.Next() {1133 var (1134 tmpId string1135 tmpFixVer string1136 tmpVer string1137 tmpStatus string1138 CreateVersionName []string1139 )1140 Issuess.Scan(&tmpId, &tmpFixVer, &tmpStatus, &tmpVer)1141 // log.Println(tmpId, tmpFixVer, tmpStatus, tmpVer)1142 IssueCreateCounter := 01143 if tmpVer != "0" {1144 VerDataSQL := " SELECT Data FROM `Version` WHERE `Id` = '" + tmpId + "' AND Enable ='1' "1145 VerDatas, err := db.Query(VerDataSQL)1146 checkerr(VerDataSQL, err)1147 for VerDatas.Next() {1148 var tmpData string1149 VerDatas.Scan(&tmpData)1150 VersNameSQL := " SELECT Name FROM `Versions` WHERE `Sn` = '" + tmpData + "' AND Project ='" + ProjectName + "' "1151 VerName := QuerySingle(VersNameSQL)1152 // log.Println("Create", VerName)1153 CreateVersionName = append(CreateVersionName, VerName)1154 for key, Value := range DiffVersionResult {1155 if Value.Name == VerName {1156 DiffVersionResult[key].CreateCounter++1157 IssueCreateCounter++1158 }1159 }1160 }1161 VerDatas.Close()1162 }1163 // log.Println("Create counter", IssueCreateCounter)1164 if tmpStatus == "Done" {1165 FixVerDataSQL := " SELECT Data FROM `Fixversion` WHERE `Id` = '" + tmpId + "' AND Enable ='1' "1166 VerDatas, err := db.Query(FixVerDataSQL)1167 checkerr(FixVerDataSQL, err)1168 for VerDatas.Next() {1169 var tmpData string1170 VerDatas.Scan(&tmpData)1171 VersNameSQL := " SELECT Name FROM `Fixversions` WHERE `Sn` = '" + tmpData + "' AND Project ='" + ProjectName + "' "1172 VerName := QuerySingle(VersNameSQL)1173 // log.Println("close", VerName)1174 for key, Value := range DiffVersionResult {1175 if Value.Name == VerName && IssueCreateCounter > 0 {1176 DiffVersionResult[key].CloseCounter++1177 IssueCreateCounter--1178 }1179 }1180 }1181 }1182 // log.Println("Close counter", IssueCreateCounter, VersionRemainCounter)1183 }1184 Issuess.Close()1185 db.Close()1186 return DiffVersionResult1187}1188func BABYIOSDiffVersion(ProjectName string) JsonResult {1189 DiffVersionResult := BABYIOSVersionData(ProjectName)1190 var ReturnJson JsonResult1191 VersionRemainCounter := 01192 for key, _ := range DiffVersionResult {1193 if key == 0 {1194 DiffVersionResult[key].RemainCounter = 01195 VersionRemainCounter = DiffVersionResult[key].CreateCounter - DiffVersionResult[key].CloseCounter1196 } else {1197 DiffVersionResult[key].RemainCounter = VersionRemainCounter1198 VersionRemainCounter = VersionRemainCounter + DiffVersionResult[key].CreateCounter - DiffVersionResult[key].CloseCounter1199 }1200 ReturnJson.Name = append(ReturnJson.Name, DiffVersionResult[key].Name)1201 ReturnJson.CreateCounter = append(ReturnJson.CreateCounter, DiffVersionResult[key].CreateCounter)1202 ReturnJson.CloseCounter = append(ReturnJson.CloseCounter, DiffVersionResult[key].CloseCounter)1203 ReturnJson.RemainCounter = append(ReturnJson.RemainCounter, DiffVersionResult[key].RemainCounter)1204 // log.Println(key, Value)1205 }1206 // log.Println(ReturnJson)1207 return ReturnJson1208}1209func BABYIOSDiffVersionSoFarRemain(ProjectName string) JsonResult {1210 ReturnJson := BABYIOSDiffVersion(ProjectName)1211 soFarClose := 01212 for Key, _ := range ReturnJson.Name {1213 tmp := ReturnJson.CloseCounter[Key]1214 if Key == 0 {1215 ReturnJson.CloseCounter[Key] = 01216 } else {1217 ReturnJson.CloseCounter[Key] = soFarClose1218 }1219 soFarClose = soFarClose + tmp1220 }1221 return ReturnJson1222}1223func BABYIOSDiffDate(ProjectName string) JsonResult {1224 var ReturnJson JsonResult1225 db, err := sql.Open("mysql", "eli:eli@/Jira_Data")1226 // Date Create1227 DateRemainCreateSQL := "SELECT count(*),CreateDate FROM (SELECT *,DATE(CreatedTime) as CreateDate FROM Issues WHERE `Reporter`='Ming_Chiang' AND `Key` LIKE '" + ProjectName + "-%' ORDER by CreatedTime) as b GROUP BY CreateDate"1228 // log.Println(DateRemainCreateSQL)1229 CreateDateRemains, err := db.Query(DateRemainCreateSQL)1230 checkerr(DateRemainCreateSQL, err)1231 var DateReaminResult []JiraIssuesDateRemain1232 for CreateDateRemains.Next() {1233 var (1234 DateRemain JiraIssuesDateRemain1235 tmpCounter int1236 tmpCreateDate string1237 )1238 CreateDateRemains.Scan(&tmpCounter, &tmpCreateDate)1239 DateRemain.Name = tmpCreateDate1240 DateRemain.CreateCounter = tmpCounter1241 DateReaminResult = append(DateReaminResult, DateRemain)1242 }1243 CreateDateRemains.Close()1244 sortutil.AscByField(DateReaminResult, "Name")1245 IssuesSQL := "SELECT Id FROM Issues WHERE `Reporter`='Ming_Chiang' AND `Status`='Done' AND `Key` like '" + ProjectName + "-%' "1246 Issuess, err := db.Query(IssuesSQL)1247 checkerr(IssuesSQL, err)1248 for Issuess.Next() {1249 var tmpId string1250 var tmpresult JiraIssuesDateRemain1251 Issuess.Scan(&tmpId)1252 HistorySQL := "SELECT date(Created) FROM `Historys` WHERE `Jid` = '" + tmpId + "' AND Tostring='Done' ORDER BY Sn DESC LIMIT 1"1253 ResolveDate := QuerySingle(HistorySQL)1254 appendflag := 01255 if ResolveDate == "" {1256 HistorySQL := "SELECT date(Created) FROM `Historys` WHERE `Jid` = '" + tmpId + "' AND Tostring='Done' ORDER BY Sn DESC LIMIT 1"1257 ResolveDate = QuerySingle(HistorySQL)1258 }1259 // log.Println("Resolve date", ResolveDate, tmpId)1260 for Key, Value := range DateReaminResult {1261 if Value.Name == ResolveDate {1262 appendflag++1263 DateReaminResult[Key].CloseCounter++1264 }1265 }1266 // log.Println(ResolveDate, tmpId, appendflag)1267 if appendflag == 0 {1268 tmpresult.Name = ResolveDate1269 tmpresult.CloseCounter++1270 DateReaminResult = append(DateReaminResult, tmpresult)1271 }1272 }1273 Issuess.Close()1274 db.Close()1275 OldResultRemain := 01276 sortutil.AscByField(DateReaminResult, "Name")1277 for key, Value := range DateReaminResult {1278 if key == 0 {1279 ReturnJson.RemainCounter = append(ReturnJson.RemainCounter, 0)1280 } else {1281 ReturnJson.RemainCounter = append(ReturnJson.RemainCounter, OldResultRemain)1282 }1283 OldResultRemain = (OldResultRemain + DateReaminResult[key].CreateCounter) - DateReaminResult[key].CloseCounter1284 ReturnJson.Name = append(ReturnJson.Name, Value.Name)1285 ReturnJson.CreateCounter = append(ReturnJson.CreateCounter, Value.CreateCounter)1286 ReturnJson.CloseCounter = append(ReturnJson.CloseCounter, Value.CloseCounter)1287 }1288 // for key, value := range ReturnJson {1289 // log.Println(ProjectName, key, value)1290 // }1291 // log.Println(ReturnJson)1292 return ReturnJson1293}1294func BABYIOSDueDateRemain(ProjectName string) []JsonResultTable {1295 //SELECT * FROM `Issues` WHERE `DueDate`!= "0000-00-00" AND Status != 'Closed' AND `Key` like 'BABY-%' ORDER BY `FixVersions` DESC1296 db, err := sql.Open("mysql", "eli:eli@/Jira_Data")1297 RemainIssueSQL := "SELECT `Key`, `Summary`, `Priority`, `Assignee` FROM `Issues` WHERE `DueDate`!= '0000-00-00' AND `Reporter`='Ming_Chiang' AND Status != 'Done' AND `Key` like '" + ProjectName + "-%' ORDER BY `FixVersions` DESC"1298 RemainIssues, err := db.Query(RemainIssueSQL)1299 checkerr(RemainIssueSQL, err)1300 var RemainIssueResult []JsonResultTable1301 for RemainIssues.Next() {1302 var tmpRemainIssue JsonResultTable1303 RemainIssues.Scan(&tmpRemainIssue.Name, &tmpRemainIssue.Summary, &tmpRemainIssue.Priority, &tmpRemainIssue.Assignee)1304 // log.Println(tmpRemainIssue)1305 RemainIssueResult = append(RemainIssueResult, tmpRemainIssue)1306 }1307 RemainIssues.Close()1308 db.Close()1309 return RemainIssueResult1310}1311func BABYIssueTimespent() []JsonResultTable {1312 db, _ := sql.Open("mysql", "eli:eli@/Jira_Data")1313 RemainIssueSQL := "SELECT a.`Key`, a.`Summary`, a.`Priority`, a.DiffDate, a.`Assignee` from " +1314 "( SELECT *,DATEDIFF(DATE(`UpdatedTime`),DATE(CURDATE() )) AS DiffDate FROM `Issues` WHERE " +1315 "(`Reporter`='Ming_Chiang' AND `Key` LIKE 'IOS-%' AND Status!='Done' AND Resolution not like '% Fix' ) OR " +1316 "(`Key` LIKE 'BABY-%' AND Status!='Closed' AND Resolution not like '% Fix' ) )as a ORDER by a.DiffDate"1317 var RemainIssueResult []JsonResultTable1318 RemainIssues, err := db.Query(RemainIssueSQL)1319 checkerr(RemainIssueSQL, err)1320 for RemainIssues.Next() {1321 var tmpRemainIssue JsonResultTable1322 RemainIssues.Scan(&tmpRemainIssue.Name, &tmpRemainIssue.Summary, &tmpRemainIssue.Priority, &tmpRemainIssue.DiffDate, &tmpRemainIssue.Assignee)1323 // log.Println(tmpRemainIssue)1324 RemainIssueResult = append(RemainIssueResult, tmpRemainIssue)1325 }1326 RemainIssues.Close()1327 sortutil.AscByField(RemainIssueResult, "DiffDate")1328 // log.Println(RemainIssueResult)1329 db.Close()1330 return RemainIssueResult1331}1332func BABYDueDateRemain() []JsonResultTable {1333 //SELECT * FROM `Issues` WHERE `DueDate`!= "0000-00-00" AND Status != 'Closed' AND `Key` like 'BABY-%' ORDER BY `FixVersions` DESC1334 db, _ := sql.Open("mysql", "eli:eli@/Jira_Data")1335 RemainIssueSQL := "SELECT `Key`, `Summary`, `Priority`, `Assignee` FROM `Issues` WHERE (`DueDate`!= '0000-00-00' AND `Reporter`='Ming_Chiang' AND Status != 'Done' AND `Key` like 'IOS-%') OR (`DueDate`!= '0000-00-00' AND Status != 'Closed' AND `Key` like 'BABY-%' )ORDER BY `FixVersions` DESC"1336 var RemainIssueResult []JsonResultTable1337 RemainIssues, err := db.Query(RemainIssueSQL)1338 checkerr(RemainIssueSQL, err)1339 for RemainIssues.Next() {1340 var tmpRemainIssue JsonResultTable1341 RemainIssues.Scan(&tmpRemainIssue.Name, &tmpRemainIssue.Summary, &tmpRemainIssue.Priority, &tmpRemainIssue.Assignee)1342 // log.Println(tmpRemainIssue)1343 RemainIssueResult = append(RemainIssueResult, tmpRemainIssue)1344 }1345 RemainIssues.Close()1346 db.Close()1347 return RemainIssueResult1348}1349func BABYDiffDate() (JsonResult, JsonResult) {1350 JsonResult_I := BABYIOSDiffDate("IOS")1351 JsonResult_A := DiffDate("BABY")1352 var newandroidjson JsonResult1353 var newiosjson JsonResult1354 var tmpName []string1355 for _, value := range JsonResult_A.Name {1356 if !stringInSlice(value, tmpName) {1357 tmpName = append(tmpName, value)1358 }1359 }1360 for _, value := range JsonResult_I.Name {1361 if !stringInSlice(value, tmpName) {1362 tmpName = append(tmpName, value)1363 }1364 }1365 sort.Strings(tmpName)1366 newandroidjson.Name = append(newandroidjson.Name, tmpName...)1367 newiosjson.Name = append(newiosjson.Name, tmpName...)1368 Androidremain := 01369 Iosremain := 01370 for _, nvalue := range newandroidjson.Name {1371 for key, value := range JsonResult_A.Name {1372 if value == nvalue {1373 Androidremain = JsonResult_A.RemainCounter[key]1374 }1375 }1376 newandroidjson.RemainCounter = append(newandroidjson.RemainCounter, Androidremain)1377 // }1378 // for _, nvalue := range newiosjson.Name {1379 for key, value := range JsonResult_I.Name {1380 if value == nvalue {1381 Iosremain = JsonResult_I.RemainCounter[key]1382 }1383 }1384 newiosjson.RemainCounter = append(newiosjson.RemainCounter, Iosremain)1385 }1386 // for Key, value := range newandroidjson.Name {1387 // log.Println(Key, value, newandroidjson.RemainCounter[Key])1388 // log.Println(Key, value, newiosjson.RemainCounter[Key])1389 // }1390 return newandroidjson, newiosjson1391}1392func BABYDiffWeek(ProjectName string) []JsonResult {1393 db, _ := sql.Open("mysql", "eli:eli@/Jira_Data")1394 APPDateReaminResult, WEBDateReaminResult := BABYDiffDate()1395 DateRemainCreateSQL := "SELECT CONCAT(yeardate ,'-' ,date ) as yearweek from (select UpdatedTime,YEAR(UpdatedTime) as yeardate,WEEKOFYEAR(UpdatedTime) as date from Issues WHERE `UpdatedTime`!='0000-00-00' AND `Key` LIKE 'TYGH-%' " +1396 " union " +1397 " select UpdatedTime,YEAR(UpdatedTime) as yeardate ,WEEKOFYEAR(CreatedTime) as date from Issues WHERE `UpdatedTime`!='0000-00-00' AND `Key` LIKE 'TYGH-%' ) as a GROUP by a.date order by UpdatedTime "1398 CreateDateRemains, err := db.Query(DateRemainCreateSQL)1399 checkerr(DateRemainCreateSQL, err)1400 var APPWeekReaminResult []JiraIssuesDateRemain1401 var WEBWeekReaminResult []JiraIssuesDateRemain1402 for CreateDateRemains.Next() {1403 var (1404 DateRemain JiraIssuesDateRemain1405 tmpCreateDate string1406 )1407 CreateDateRemains.Scan(&tmpCreateDate)1408 if tmpCreateDate != "" {1409 DateRemain.Name = tmpCreateDate1410 APPWeekReaminResult = append(APPWeekReaminResult, DateRemain)1411 WEBWeekReaminResult = append(WEBWeekReaminResult, DateRemain)1412 }1413 }1414 CreateDateRemains.Close()1415 db.Close()1416 // log.Println(WEBDateReaminResult)1417 layout := "2006-01-02"1418 for key, value := range APPDateReaminResult.Name {1419 t, err := time.Parse(layout, value)1420 if err != nil {1421 log.Println(err)1422 }1423 isoYear, isoWeek := t.ISOWeek()1424 // log.Println(isoWeek, value)1425 sisoWeek := strconv.Itoa(isoWeek)1426 sisoYear := strconv.Itoa(isoYear)1427 yearweekStr := sisoYear + "-" + sisoWeek1428 // log.Println(value, yearweekStr)1429 for index, weeknumber := range APPWeekReaminResult {1430 if weeknumber.Name == yearweekStr {1431 // log.Println(index, key, weeknumber.Name, yearweekStr)1432 APPWeekReaminResult[index].RemainCounter = APPDateReaminResult.RemainCounter[key]1433 WEBWeekReaminResult[index].RemainCounter = WEBDateReaminResult.RemainCounter[key]1434 }1435 }1436 }1437 now := time.Now()1438 year, week := now.ISOWeek()1439 todayisoWeek := strconv.Itoa(week)1440 todayisoYear := strconv.Itoa(year)1441 todayyearweekStr := todayisoYear + "-" + todayisoWeek1442 var ReturnJsonAPP JsonResult1443 var ReturnJsonWEB JsonResult1444 for key, _ := range WEBWeekReaminResult {1445 if WEBWeekReaminResult[key].Name != todayyearweekStr {1446 ReturnJsonWEB.Name = append(ReturnJsonWEB.Name, WEBWeekReaminResult[key].Name)1447 ReturnJsonWEB.RemainCounter = append(ReturnJsonWEB.RemainCounter, WEBWeekReaminResult[key].RemainCounter)1448 ReturnJsonAPP.Name = append(ReturnJsonAPP.Name, APPWeekReaminResult[key].Name)1449 ReturnJsonAPP.RemainCounter = append(ReturnJsonAPP.RemainCounter, APPWeekReaminResult[key].RemainCounter)1450 }1451 }1452 // log.Println("APP", APPWeekReaminResult)1453 // log.Println("WEB", WEBWeekReaminResult)1454 var ReturnResult []JsonResult1455 ReturnResult = append(ReturnResult, ReturnJsonAPP, ReturnJsonWEB)1456 return ReturnResult1457}1458func ProjectSummary(ProjectName string) []ProjectSummaryTable {1459 db, _ := sql.Open("mysql", "eli:eli@/Jira_Data")1460 RemainIssueSQL := "SELECT `Project`,`Version`,`FileName`,floor(`Scenario`),floor(`Auto`),floor(`BDI`),floor(`Compatibility`),floor(`Security`),floor(`Other`),floor(`Battery`),DATE(`Date`) FROM `Projectsummary` WHERE Project='" + ProjectName + "' order by `Date` DESC"1461 var RemainIssueResult []ProjectSummaryTable1462 RemainIssues, err := db.Query(RemainIssueSQL)1463 checkerr(RemainIssueSQL, err)1464 for RemainIssues.Next() {1465 var tmpRemainIssue ProjectSummaryTable1466 RemainIssues.Scan(&tmpRemainIssue.Project, &tmpRemainIssue.Version, &tmpRemainIssue.FileName, &tmpRemainIssue.Scenario, &tmpRemainIssue.Auto, &tmpRemainIssue.BDI, &tmpRemainIssue.Compatibility, &tmpRemainIssue.Security, &tmpRemainIssue.Other, &tmpRemainIssue.Battery, &tmpRemainIssue.Date)1467 // log.Println(tmpRemainIssue)1468 RemainIssueResult = append(RemainIssueResult, tmpRemainIssue)1469 }1470 RemainIssues.Close()1471 db.Close()1472 return RemainIssueResult1473}1474func ListProjectSummaryColumn() []ListColumn {1475 db, _ := sql.Open("mysql", "eli:eli@/Jira_Data")1476 ProjectSummaryColumnSQL := "SELECT `Project`,`Version`,`FileName`,`Scenario`,`Auto`,`BDI`,`Compatibility`,`Security`,`Other`,`Battery`,`Date` FROM `Projectsummary` WHERE 1 limit 1"1477 ProjectSummarys, err := db.Query(ProjectSummaryColumnSQL)1478 checkerr(ProjectSummaryColumnSQL, err)1479 ColumnProjectSummary, err := ProjectSummarys.Columns()1480 var ResultList []ListColumn1481 for _, element := range ColumnProjectSummary {1482 var tmpResult ListColumn1483 tmpResult.Column = element1484 // tmpResult.Selection = 01485 ResultList = append(ResultList, tmpResult)1486 }1487 ProjectSummarys.Close()1488 db.Close()1489 return ResultList1490}1491func BABYDiffWeekDate(ProjectName string, YearWeek string) []JsonResult {1492 // specific week data1493 var APPWeekDateReaminResult []JiraIssuesDateRemain1494 var WEBWeekDateReaminResult []JiraIssuesDateRemain1495 s := strings.Split(YearWeek, "-")1496 sisoYear, sisoWeek := s[0], s[1]1497 isoYear, _ := strconv.Atoi(sisoYear)1498 isoWeek, _ := strconv.Atoi(sisoWeek)1499 tmpWeekFullName := WeekWorkDayArray(isoYear, isoWeek)1500 for _, value := range tmpWeekFullName {1501 var DateRemain JiraIssuesDateRemain1502 DateRemain.Name = value1503 APPWeekDateReaminResult = append(APPWeekDateReaminResult, DateRemain)1504 WEBWeekDateReaminResult = append(WEBWeekDateReaminResult, DateRemain)1505 }1506 APPDateReaminResult, WEBDateReaminResult := BABYDiffDate()1507 lastAPPremain := 01508 lastWEBremain := 01509 for key, _ := range WEBDateReaminResult.Name {1510 for Key, _ := range WEBWeekDateReaminResult {1511 if WEBWeekDateReaminResult[Key].Name == WEBDateReaminResult.Name[key] {1512 WEBWeekDateReaminResult[Key].RemainCounter = WEBDateReaminResult.RemainCounter[key]1513 if lastWEBremain == 0 {1514 lastWEBremain = WEBDateReaminResult.RemainCounter[key-1]1515 }1516 }1517 }1518 for Key, _ := range APPWeekDateReaminResult {1519 if APPWeekDateReaminResult[Key].Name == APPDateReaminResult.Name[key] {1520 APPWeekDateReaminResult[Key].RemainCounter = APPDateReaminResult.RemainCounter[key]1521 if lastAPPremain == 0 {1522 lastAPPremain = APPDateReaminResult.RemainCounter[key-1]1523 }1524 }1525 }1526 }1527 var ReturnJsonAPP JsonResult1528 var ReturnJsonWEB JsonResult1529 var oldwebremain, oldappremain int1530 for key, _ := range WEBWeekDateReaminResult {1531 ReturnJsonWEB.Name = append(ReturnJsonWEB.Name, WEBWeekDateReaminResult[key].Name)1532 if WEBWeekDateReaminResult[key].RemainCounter != 0 {1533 oldwebremain = WEBWeekDateReaminResult[key].RemainCounter1534 lastWEBremain = oldwebremain1535 } else {1536 WEBWeekDateReaminResult[key].RemainCounter = lastWEBremain1537 }1538 if APPWeekDateReaminResult[key].RemainCounter != 0 {1539 oldappremain = APPWeekDateReaminResult[key].RemainCounter1540 lastAPPremain = oldappremain1541 } else {1542 APPWeekDateReaminResult[key].RemainCounter = lastAPPremain1543 }1544 oldwebremain = WEBWeekDateReaminResult[key].RemainCounter1545 ReturnJsonWEB.RemainCounter = append(ReturnJsonWEB.RemainCounter, WEBWeekDateReaminResult[key].RemainCounter)1546 ReturnJsonAPP.Name = append(ReturnJsonAPP.Name, APPWeekDateReaminResult[key].Name)1547 oldappremain = APPWeekDateReaminResult[key].RemainCounter1548 ReturnJsonAPP.RemainCounter = append(ReturnJsonAPP.RemainCounter, APPWeekDateReaminResult[key].RemainCounter)1549 }1550 var ReturnResult []JsonResult1551 ReturnResult = append(ReturnResult, ReturnJsonAPP, ReturnJsonWEB)1552 return ReturnResult1553}...

Full Screen

Full Screen

createLottery.go

Source:createLottery.go Github

copy

Full Screen

1package events2import (3 "github.com/gin-gonic/gin"4 "math"5 "math/rand"6 "net/http"7)8type itemPrice int9const (10 epicItem itemPrice = 7211 rareItem itemPrice = 2412 unusualItem itemPrice = 613 usualItem itemPrice = 214 lowQualityItem itemPrice = 115 minPotentialWinnersPart = 0.1516 maxPotentialWinnersPart = 0.3517 potentialWinnerStep = maxPotentialWinnersPart - minPotentialWinnersPart18)19type lotteryCreatorError string20func (l lotteryCreatorError) Error() string {21 return string(l)22}23type LotteryObject struct {24 Epic int `json:"epic"`25 Rare int `json:"rare"`26 Unusual int `json:"unusual"`27 Usual int `json:"usual"`28 Low int `json:"low"`29}30type RespondLotteryObject struct {31 ParticipantsCount int `json:"participantsCount"`32 BankPerParticipant float64 `json:"bankPerParticipant"`33 Bank float64 `json:"bank"`34 BankRemain float64 `json:"bankRemain"`35 PotentialWinners int `json:"potentialWinners"`36 Lottery LotteryObject `json:"lottery"`37}38type LotteryCreator struct {39 ParticipantsCount int `json:"participantsCount" binding:"required"`40 Rate int `json:"rate" binding:"required"`41 QualityOverQuantityMode bool `json:"qualityOverQuantityMode"`42}43func (r *RespondLotteryObject) generateLotteryObject(qualityOverQuantityMode bool) {44 if qualityOverQuantityMode {45 for r.BankRemain >= 1 {46 switch {47 case r.BankRemain >= float64(epicItem):48 r.Lottery.Epic++49 r.BankRemain -= float64(epicItem)50 case r.BankRemain >= float64(rareItem):51 r.Lottery.Rare++52 r.BankRemain -= float64(rareItem)53 case r.BankRemain >= float64(unusualItem):54 r.Lottery.Unusual++55 r.BankRemain -= float64(unusualItem)56 case r.BankRemain >= float64(usualItem):57 r.Lottery.Usual++58 r.BankRemain -= float64(usualItem)59 case r.BankRemain >= float64(lowQualityItem):60 r.Lottery.Low++61 r.BankRemain -= float64(lowQualityItem)62 default:63 break64 }65 }66 } else {67 potentialWinners := r.PotentialWinners68 potentialWinnersLoop:69 for r.PotentialWinners > 0 {70 bankForParticipantLeft := r.BankRemain / float64(potentialWinners)71 switch {72 case r.BankRemain > float64(epicItem) && bankForParticipantLeft >= 9:73 r.Lottery.Epic++74 r.BankRemain -= float64(epicItem)75 potentialWinners--76 case r.BankRemain > float64(rareItem) && bankForParticipantLeft >= 4.5:77 r.Lottery.Rare++78 r.BankRemain -= float64(rareItem)79 potentialWinners--80 case r.BankRemain > float64(unusualItem) && bankForParticipantLeft >= 2:81 r.Lottery.Unusual++82 r.BankRemain -= float64(unusualItem)83 potentialWinners--84 case r.BankRemain > float64(usualItem) && bankForParticipantLeft >= 1.2:85 r.Lottery.Usual++86 r.BankRemain -= float64(usualItem)87 potentialWinners--88 default:89 break potentialWinnersLoop90 }91 }92 if r.BankRemain >= 1 {93 r.generateLotteryObject(true)94 }95 }96}97func (l LotteryCreator) generateLottery() RespondLotteryObject {98 var respond RespondLotteryObject99 respond.ParticipantsCount = l.ParticipantsCount100 respond.BankPerParticipant = getBankPerParticipant(l.Rate)101 respond.Bank = float64(l.ParticipantsCount) * respond.BankPerParticipant102 respond.BankRemain = respond.Bank103 respond.PotentialWinners = int(math.Round(104 float64(l.ParticipantsCount) * (maxPotentialWinnersPart - (potentialWinnerStep * rand.Float64()))))105 respond.Lottery = LotteryObject{0, 0, 0, 0, 0}106 respond.generateLotteryObject(l.QualityOverQuantityMode)107 return respond108}109func getBankPerParticipant(rate int) float64 {110 switch {111 case rate >= 13:112 return 4.5113 case rate >= 10 && rate <= 12:114 return 3115 case rate >= 7 && rate <= 9:116 return 1.5117 default:118 return 0119 }120}121func CreateLottery(c *gin.Context) {122 var lotteryCreator LotteryCreator123 if err := c.BindJSON(&lotteryCreator); err != nil {124 c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})125 return126 }127 if lotteryCreator.Rate < 7 {128 c.JSON(http.StatusBadRequest, gin.H{"error": lotteryCreatorError("Lottery could be created for rate 7 and more")})129 return130 }131 if lotteryCreator.ParticipantsCount < 10 {132 c.JSON(http.StatusBadRequest, gin.H{"error": lotteryCreatorError("Lottery could be created for more than 10 participants.")})133 return134 }135 respond := lotteryCreator.generateLottery()136 c.JSON(http.StatusOK, respond)137}...

Full Screen

Full Screen

po_goods.go

Source:po_goods.go Github

copy

Full Screen

...14 Blessing sql.NullString `json:"blessing" db:"blessing"` // 祝福语15 Amount decimal.Decimal `json:"amount" db:"amount"` // 红包总金额16 AmountOne decimal.Decimal `json:"amountOne" db:"amount_one"` // 单个红包金额,碰运气红包无效17 Quantity int `json:"quantity" db:"quantity"` // 红包总数量18 RemainAmount decimal.Decimal `json:"remainAmount" db:"remain_amount"` // 红包剩余金额额19 RemainQuantity int `json:"remainQuantity" db:"remain_quantity"` // 红包剩余数量20 ExpiredAt time.Time `json:"expiredAt" db:"expired_at"` // 过期时间21 Status services.OrderStatus `json:"status" db:"status"` // 红包状态:0红包初始化,1启用,2失效22 OrderType services.OrderType `json:"orderType" db:"order_type"` // 订单类型:发布单、退款单23 PayStatus services.PayStatus `json:"payStatus" db:"pay_status"` // 支付状态:未支付,支付中,已支付,支付失败24 CreatedAt time.Time `json:"createdAt" db:"created_at,omitempty"` // 创建时间25 UpdatedAt time.Time `json:"updatedAt" db:"updated_at,omitempty"` // 更新时间26 OriginEnvelopeNo string `json:"originEnvelopeNo" db:"origin_envelope_no"` // 原先关联的红包编号27}28func (po *RedEnvelopeGoods) ToDTO() *services.RedEnvelopeGoodsDTO {29 dto := &services.RedEnvelopeGoodsDTO{30 EnvelopeNo: po.EnvelopeNo,31 EnvelopeType: po.EnvelopeType,32 Username: po.Username.String,33 UserId: po.UserId,...

Full Screen

Full Screen

remain

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 var jsonBlob = []byte(`[4 {"Name": "Platypus", "Order": "Monotremata"},5 {"Name": "Quoll", "Order": "Dasyuromorphia"}6 type Animal struct {7 }8 err := json.Unmarshal(jsonBlob, &animals)9 if err != nil {10 fmt.Println("error:", err)11 }12 fmt.Printf("%+v13}14import (15func main() {16 var jsonBlob = []byte(`[17 {"Name": "Platypus", "Order": "Monotremata"},18 {"Name": "Quoll", "Order": "Dasyuromorphia"}19 type Animal struct {20 }21 animals := []Animal{}22 err := json.NewDecoder(os.Stdin).Decode(&animals)23 if err != nil {24 fmt.Println("error:", err)25 }26 fmt.Printf("%+v27}28import (29func main() {30 type Response1 struct {31 }32 res1D := &Response1{33 Fruits: []string{"apple", "peach", "pear"}}34 res1B, _ := json.Marshal(res1D)35 fmt.Println(string(res1B))36 type Response2 struct {37 }38 res2D := &Response2{39 Fruits: []string{"apple", "peach", "pear"}}40 res2B, _ := json.Marshal(res2D)41 fmt.Println(string(res2B))42 res2D = &Response2{}43 json.Unmarshal(res2B, &res2D)44 fmt.Println(res2D)45 fmt.Println(res2D.Fruits[0])

Full Screen

Full Screen

remain

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 var jsonBlob = []byte(`[4 {"Name": "Platypus", "Order": "Monotremata"},5 {"Name": "Quoll", "Order": "Dasyuromorphia"}6 type Animal struct {7 }8 err := json.Unmarshal(jsonBlob, &animals)9 if err != nil {10 fmt.Println("error:", err)11 }12 fmt.Printf("%+v", animals)13}14import (15func main() {16 var jsonBlob = []byte(`[17 {"Name": "Platypus", "Order": "Monotremata"},18 {"Name": "Quoll", "Order": "Dasyuromorphia"}19 type Animal struct {20 }21 err := json.Unmarshal(jsonBlob, &animals)22 if err != nil {23 fmt.Println("error:", err)24 }25 fmt.Printf("%+v", animals)26}27import (28func main() {29 enc := json.NewEncoder(os.Stdout)30 d := map[string]int{"apple": 5, "lettuce": 7}31 enc.Encode(d)32}33import (34func main() {35 dec := json.NewDecoder(os.Stdin)36 for {37 var v interface{}38 if err := dec.Decode(&v);

Full Screen

Full Screen

remain

Using AI Code Generation

copy

Full Screen

1import (2type Person struct {3}4func main() {5 p1 := Person{"James", "Bond", 20}6 bs, _ := json.Marshal(p1)7 fmt.Println(bs)8 fmt.Printf("%T \n", bs)9 fmt.Println(string(bs))10}11import (12type Person struct {13}14func main() {15 bs := []byte(`{"First":"James","Last":"Bond","Age":20}`)16 json.Unmarshal(bs, &p1)17 fmt.Println(p1.First)18 fmt.Println(p1.Last)19 fmt.Println(p1.Age)20}21import (22type Person struct {23}24func main() {25 p1 := Person{"James", "Bond", 20}26 json.NewEncoder(os.Stdout).Encode(p1)27}28import (29type Person struct {30}31func main() {32 rdr := strings.NewReader(`{"First":"James","Last":"Bond","Age":20}`)33 json.NewDecoder(rdr).Decode(&p1)34 fmt.Println(p1.First)35 fmt.Println(p1.Last)36 fmt.Println(p1.Age)37}

Full Screen

Full Screen

remain

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 var jsonString = []byte(`{"name":"john wick","age":27}`)4 var data map[string]interface{}5 var err = json.Unmarshal(jsonString, &data)6 if err != nil {7 fmt.Println(err.Error())8 }9 fmt.Println("user name:", data["name"])10 fmt.Println("user age:", data["age"])11 var age = data["age"].(float64)12 fmt.Println("user age:", age)13 var name = data["name"].(string)14 fmt.Println("user name:", name)15}16import (17func main() {18 var data = map[string]interface{}{19 }20 var jsonString, err = json.Marshal(data)21 if err != nil {22 fmt.Println(err.Error())23 }24 fmt.Println(string(jsonString))25}26{"name":"john wick","age":27}27import (28func main() {29 var data = map[string]interface{}{30 }

Full Screen

Full Screen

remain

Using AI Code Generation

copy

Full Screen

1import (2type Student struct {3}4func main() {5 s := Student{6 }7 bs, err := json.Marshal(s)8 if err != nil {9 fmt.Println(err)10 }11 fmt.Println(string(bs))12}13import (14type Student struct {15}16func main() {17 s := Student{18 }19 bs, err := json.Marshal(s)20 if err != nil {21 fmt.Println(err)22 }23 fmt.Println(string(bs))24 json.Unmarshal(bs, &s)25 fmt.Println(s)26 file, err := os.Create("data.txt")27 if err != nil {28 fmt.Println(err)29 }30 encoder := json.NewEncoder(file)31 err = encoder.Encode(s)32 if err != nil {33 fmt.Println(err)34 }35 file, err = os.Open("data.txt")36 if err != nil {37 fmt.Println(err)38 }39 decoder := json.NewDecoder(file)40 err = decoder.Decode(&s)41 if err != nil {42 fmt.Println(err)43 }44 fmt.Println(s)45}46import (47type Student struct {48}49func main() {50 s := Student{51 }52 bs, err := json.Marshal(s)53 if err != nil {54 fmt.Println(err)55 }56 fmt.Println(string(bs))

Full Screen

Full Screen

remain

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 var data = []byte(`{"name":"john wick","age":27}`)4 var obj map[string]interface{}5 json.Unmarshal(data, &obj)6 fmt.Println("name:", obj["name"])7 fmt.Println("age:", obj["age"])8}9Related Posts: Golang json Marshal() method10Golang json Unmarshal() method11Golang json MarshalIndent() method12Golang json NewEncoder() method13Golang json NewDecoder() method14Golang json Decoder.Decode() method15Golang json Encoder.Encode() method16Golang json Valid() method17Golang json Indent() method18Golang json Compact() method19Golang json Marshaler.MarshalJSON() method20Golang json Unmarshaler.UnmarshalJSON() method21Golang json Marshaler.MarshalText() method22Golang json Unmarshaler.UnmarshalText() method23Golang json Marshaler.MarshalXML() method24Golang json Unmarshaler.UnmarshalXML() method25Golang json Marshaler.MarshalXMLAttr() method26Golang json Unmarshaler.UnmarshalXMLAttr() method27Golang json Marshaler.MarshalXML() method28Golang json Unmarshaler.UnmarshalXML() method29Golang json Marshaler.MarshalXMLAttr() method30Golang json Unmarshaler.UnmarshalXMLAttr() method31Golang json Marshaler.MarshalXML() method32Golang json Unmarshaler.UnmarshalXML() method33Golang json Marshaler.MarshalXMLAttr() method34Golang json Unmarshaler.UnmarshalXMLAttr() method35Golang json Marshaler.MarshalXML() method36Golang json Unmarshaler.UnmarshalXML() method37Golang json Marshaler.MarshalXMLAttr() method38Golang json Unmarshaler.UnmarshalXMLAttr() method39Golang json Marshaler.MarshalXML() method40Golang json Unmarshaler.UnmarshalXML() method41Golang json Marshaler.MarshalXMLAttr() method42Golang json Unmarshaler.UnmarshalXMLAttr() method43Golang json Marshaler.MarshalXML() method44Golang json Unmarshaler.UnmarshalXML() method45Golang json Marshaler.MarshalXMLAttr() method46Golang json Unmarshaler.UnmarshalXMLAttr() method

Full Screen

Full Screen

remain

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 jsonData := []byte(`{"name":"john","age":30}`)4 decoder := json.NewDecoder(bytes.NewReader(jsonData))5 var data map[string]interface{}6 err := decoder.Decode(&data)7 if err != nil {8 fmt.Println(err)9 }10 fmt.Println("data:", data)11 remainBytes, err := decoder.Buffered()12 if err != nil {13 fmt.Println(err)14 }15 fmt.Println("remain bytes:", string(remainBytes))16}17import (18func main() {19 jsonData := []byte(`{"name":"john","age":30}`)20 decoder := json.NewDecoder(bytes.NewReader(jsonData))21 var data map[string]interface{}22 err := decoder.Decode(&data)23 if err != nil {24 fmt.Println(err)25 }26 fmt.Println("data:", data)27 remainBytes, err := decoder.Buffered()28 if err != nil {29 fmt.Println(err)30 }31 fmt.Println("remain bytes:", string(remainBytes))32}33import (34func main() {35 jsonData := []byte(`{"name":"john","age":30}`)36 decoder := json.NewDecoder(bytes.NewReader(jsonData))37 var data map[string]interface{}38 err := decoder.Decode(&data)39 if err != nil {40 fmt.Println(err)41 }42 fmt.Println("data:", data)43 remainBytes, err := decoder.Buffered()44 if err != nil {45 fmt.Println(err)

Full Screen

Full Screen

remain

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 map1 := make(map[string]interface{})4 jsonObj, err := json.Marshal(map1)5 if err != nil {6 fmt.Println(err)7 }8 fmt.Println(string(jsonObj))9}10{"name":"Raj","age":23,"status":true,"salary":20000,"address":"Bangalore"}113. MarshalIndent() method12import (13func main() {14 map1 := make(map[string]interface{})15 jsonObj, err := json.MarshalIndent(map1, "", " ")16 if err != nil {17 fmt.Println(err)18 }19 fmt.Println(string(jsonObj))20}21{22}234. Unmarshal() method

Full Screen

Full Screen

remain

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 jsonString := `{"Name":"Rajeev", "Age": 25, "Occupation": "Programmer"}`4 decoder := json.NewDecoder(strings.NewReader(jsonString))5 var data map[string]interface{}6 err := decoder.Decode(&data)7 if err != nil {8 panic(err)9 }10 fmt.Println(data)11 remain := decoder.Buffered()12 fmt.Println(string(remain))13}

Full Screen

Full Screen

remain

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 jsonData := []byte(`{"Name":"Alex","Age":25,"City":"New York"}`)4 var data map[string]interface{}5 json.Unmarshal(jsonData, &data)6 fmt.Println(data)7 remain := json.NewDecoder(jsonData)8 remain.Decode(&data)9 fmt.Println(data)10}

Full Screen

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful