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
| func newModel(opts ...Option) (*defaultDataModel, error) { e := &Options{ Addr: "127.0.0.1:9999", Database: "database", } for _, o := range opts { o(e) }
connStr := fmt.Sprintf( "tcp://%s?database=%s&username=%s&password=%s&read_timeout=10&write_timeout=20", e.Addr, e.Database, e.Username, e.Password) newLogger := logger.New( log.New(os.Stdout, "\r\n", log.LstdFlags), logger.Config{ LogLevel: logger.Info, Colorful: false, }, )
db, err := gorm.Open(clickhouse.Open(connStr), &gorm.Config{ Logger: newLogger, }) if err != nil { return nil, err } return &defaultGopacketDataModel{ db: db, table: "`tableA`", }, nil }
|