Golang Package Result set

Source: Internet
Author: User
This is a creation in Article, where the information may have evolved or changed.

I've been looking for a lot of result set encapsulation is not very good, so I encapsulated the next.

Strfirsttoupper the first letter of a string into uppercase

/** * Package result set * /funcRowresult (Rows *sql. Rows) []Interface{} {//Dictionary type    //Constructs Scanargs, values two arrays, each value of Scanargs points to the address of values correspondingColumns, _: = Rows. Columns () Values: = Make([]sql. Rawbytes,Len(columns)) Scanargs: = Make([]Interface{},Len(values)) forI: =RangeValues {Scanargs[i] = &values[i]}varReturnarrs []Interface{} forRows. Next () {err: = rows. Scan (Scanargs ...)ifErr! =Nil{Panic(Err. Error ())}varValuestringRelativjson: = Newbeemap () forI, col: =RangeValues {ifCol = =Nil{value =""}Else{value =string(COL)}ifRelativjson.set (Strfirsttoupper (Columns[i]), value) {Continue}} Returnarrs =Append(Returnarrs, RELATIVJSON.BM)}returnReturnarrs}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.