예제 #1
0
func main() {
	var (
		id   int
		name string
	)
	db = database.CreateConnection()
	rows := readRows()
	defer rows.Close()
	for rows.Next() {
		err := rows.Scan(&id, &name)
		helper.CheckError(err)
		fmt.Println(id, name)
	}
	name, num := readJson()
	fmt.Println(name, num)
	db.Close()
}
예제 #2
0
func readJson() (string, int) {
	var data = []byte(`{"mahesh" :{"a":12, "b1":{"as":123}}}`)
	/*var result map[string]map[string]interface{}
	  if err := json.Unmarshal(data, &result); err != nil {
	    fmt.Println("error", err)
	  }
	  fmt.Println("status value: \a", result["mahesh"]["a"])
	*/
	/*var parsed interface{}
	  err := json.Unmarshal(data, &parsed)
	  helper.CheckError(err)
	  fmt.Println(parsed[:mahesh])
	*/
	var mahi Mahesh1
	err := json.Unmarshal(data, &mahi)
	helper.CheckError(err)
	fmt.Println(mahi.Mahesh.B1)
	readDir()
	return "m123", 10
}
예제 #3
0
func readRows() *sql.Rows {
	rows, err := db.Query("SELECT id, name from user_details where id=$1", 1)
	helper.CheckError(err)
	return rows
}