MCPcopy
hub / github.com/tinode/chat / main

Function main

tinode-db/main.go:194–359  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

192}
193
194func main() {
195 reset := flag.Bool("reset", false, "force database reset")
196 upgrade := flag.Bool("upgrade", false, "perform database version upgrade")
197 noInit := flag.Bool("no_init", false, "check that database exists but don't create if missing")
198 addRoot := flag.String("add_root", "", "create ROOT user, auth scheme 'basic'")
199 makeRoot := flag.String("make_root", "", "promote ordinary user to ROOT, auth scheme 'basic'")
200 datafile := flag.String("data", "", "name of file with sample data to load")
201 conffile := flag.String("config", "./tinode.conf", "config of the database connection")
202
203 flag.Parse()
204
205 var data Data
206 if *datafile != "" && *datafile != "-" {
207 raw, err := os.ReadFile(*datafile)
208 if err != nil {
209 log.Fatalln("Failed to read sample data file:", err)
210 }
211 err = json.Unmarshal(raw, &data)
212 if err != nil {
213 log.Fatalln("Failed to parse sample data:", err)
214 }
215 }
216
217 rand.Seed(time.Now().UnixNano())
218 data.datapath, _ = filepath.Split(*datafile)
219
220 var config configType
221 if file, err := os.Open(*conffile); err != nil {
222 log.Fatalln("Failed to read config file:", err)
223 } else {
224 jr := jcr.New(file)
225 if err = json.NewDecoder(jr).Decode(&config); err != nil {
226 switch jerr := err.(type) {
227 case *json.UnmarshalTypeError:
228 lnum, cnum, _ := jr.LineAndChar(jerr.Offset)
229 log.Fatalf("Unmarshall error in config file in %s at %d:%d (offset %d bytes): %s",
230 jerr.Field, lnum, cnum, jerr.Offset, jerr.Error())
231 case *json.SyntaxError:
232 lnum, cnum, _ := jr.LineAndChar(jerr.Offset)
233 log.Fatalf("Syntax error in config file at %d:%d (offset %d bytes): %s",
234 lnum, cnum, jerr.Offset, jerr.Error())
235 default:
236 log.Fatal("Failed to parse config file: ", err)
237 }
238 }
239 }
240
241 err := store.Store.Open(1, config.StoreConfig)
242 defer store.Store.Close()
243
244 adapterVersion := store.Store.GetAdapterVersion()
245 databaseVersion := 0
246 if store.Store.IsOpen() {
247 databaseVersion = store.Store.GetDbVersion()
248 }
249 log.Printf("Database adapter: '%s'; version: %d", store.Store.GetAdapterName(), adapterVersion)
250
251 var created bool

Callers

nothing calls this directly

Calls 15

ParseUserIdFunction · 0.92
genDbFunction · 0.85
getPasswordFunction · 0.85
ErrorMethod · 0.80
ContainsMethod · 0.80
PrintlnMethod · 0.80
UidMethod · 0.80
OpenMethod · 0.65
CloseMethod · 0.65
GetAdapterVersionMethod · 0.65
IsOpenMethod · 0.65
GetDbVersionMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…