/
main.go
77 lines (71 loc) · 1.45 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package main
import (
"database/sql"
"encoding/json"
"fmt"
"github.com/haldarmahesh/dbconnect/database"
"github.com/haldarmahesh/dbconnect/helper"
_ "github.com/haldarmahesh/string"
_ "github.com/lib/pq"
"io/ioutil"
_ "log"
)
var db *sql.DB
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()
}
func readRows() *sql.Rows {
rows, err := db.Query("SELECT id, name from user_details where id=$1", 1)
helper.CheckError(err)
return rows
}
type As struct {
As int `json:"as"`
}
type B1 struct {
A int `json:"a"`
B1 As
}
type Mahesh1 struct {
Mahesh B1
}
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
}
func readDir() {
files, _ := ioutil.ReadDir("./")
for _, f := range files {
fmt.Println(f.Name(), " &&")
}
}