本文整理汇总了Golang中github.com/ardanlabs/kit/cfg.MustURL函数的典型用法代码示例。如果您正苦于以下问题:Golang MustURL函数的具体用法?Golang MustURL怎么用?Golang MustURL使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了MustURL函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: runTest
// runTest initializes the environment for the tests and allows for
// the proper return code if the test fails or succeeds.
func runTest(m *testing.M) int {
// Initialize the configuration and logging systems. Plus anything
// else the web app layer needs.
tests.Init("XENIA")
// Initialize MongoDB using the `tests.TestSession` as the name of the
// master session.
if err := db.RegMasterSession(tests.Context, tests.TestSession, cfg.MustURL("MONGO_URI").String(), 0); err != nil {
fmt.Println("Can't register master session: " + err.Error())
return 1
}
db, err := db.NewMGO(tests.Context, tests.TestSession)
if err != nil {
fmt.Println("MongoDB is not configured")
return 1
}
defer db.CloseMGO(tests.Context)
if err := loadTestData(tests.Context, db); err != nil {
fmt.Println("test data is not loaded: " + err.Error())
return 1
}
defer unloadTestData(tests.Context, db)
return m.Run()
}
示例2: runTest
// runTest initializes the environment for the tests and allows for
// the proper return code if the test fails or succeeds.
func runTest(m *testing.M) int {
// Initialize MongoDB using the `tests.TestSession` as the name of the
// master session.
if err := db.RegMasterSession(tests.Context, tests.TestSession, cfg.MustURL("MONGO_URI").String(), 0); err != nil {
fmt.Println("Can't register master session: " + err.Error())
return 1
}
// Setup the app for performing tests.
a = routes.API()
// Snatch the mongo session so we can create some test data.
db, err := db.NewMGO(tests.Context, tests.TestSession)
if err != nil {
fmt.Println("Unable to get Mongo session")
return 1
}
defer db.CloseMGO(tests.Context)
// Generate the test data.
tstdata.Generate(db)
defer tstdata.Drop(db)
// Load in the submissions from the fixture.
if err = loadSubmissions(db); err != nil {
fmt.Println("Unable to load submissions: ", err)
}
defer aggfix.Remove(tests.Context, db, "")
return m.Run()
}
示例3: loadTestData
// loadTestData adds all the test data into the database.
func loadTestData(context interface{}, db *db.DB) error {
// Make sure the old data is clear.
if err := unloadTestData(context, db); err != nil {
if !graph.IsQuadNotExist(err) {
return err
}
}
// -----------------------------------------------------------
// Load example items, relationships, views, and patterns.
items, rels, vs, pats, err := wirefix.Get()
if err != nil {
return err
}
if err := wirefix.Add(context, db, items, rels, vs, pats); err != nil {
return err
}
// -----------------------------------------------------------
// Build the example graph.
mongoURI := cfg.MustURL("MONGO_URI")
if err := cayleyshelf.InitQuadStore(mongoURI.String()); err != nil {
return err
}
var quads []quad.Quad
quads = append(quads, quad.Make(wirePrefix+"d1dfa366-d2f7-4a4a-a64f-af89d4c97d82", wirePrefix+"on", wirePrefix+"c1b2bbfe-af9f-4903-8777-bd47c4d5b20a", ""))
quads = append(quads, quad.Make(wirePrefix+"6eaaa19f-da7a-4095-bbe3-cee7a7631dd4", wirePrefix+"on", wirePrefix+"c1b2bbfe-af9f-4903-8777-bd47c4d5b20a", ""))
quads = append(quads, quad.Make(wirePrefix+"d16790f8-13e9-4cb4-b9ef-d82835589660", wirePrefix+"on", wirePrefix+"c1b2bbfe-af9f-4903-8777-bd47c4d5b20a", ""))
quads = append(quads, quad.Make(wirePrefix+"80aa936a-f618-4234-a7be-df59a14cf8de", wirePrefix+"authored", wirePrefix+"d1dfa366-d2f7-4a4a-a64f-af89d4c97d82", ""))
quads = append(quads, quad.Make(wirePrefix+"80aa936a-f618-4234-a7be-df59a14cf8de", wirePrefix+"authored", wirePrefix+"6eaaa19f-da7a-4095-bbe3-cee7a7631dd4", ""))
quads = append(quads, quad.Make(wirePrefix+"a63af637-58af-472b-98c7-f5c00743bac6", wirePrefix+"authored", wirePrefix+"d16790f8-13e9-4cb4-b9ef-d82835589660", ""))
quads = append(quads, quad.Make(wirePrefix+"a63af637-58af-472b-98c7-f5c00743bac6", wirePrefix+"flagged", wirePrefix+"80aa936a-f618-4234-a7be-df59a14cf8de", ""))
tx := cayley.NewTransaction()
for _, quad := range quads {
tx.AddQuad(quad)
}
if err := db.NewCayley(tests.Context, tests.TestSession); err != nil {
return err
}
store, err := db.GraphHandle(tests.Context)
if err != nil {
return err
}
defer store.Close()
if err := store.ApplyTransaction(tx); err != nil {
return err
}
return nil
}
示例4: runTest
// runTest initializes the environment for the tests and allows for
// the proper return code if the test fails or succeeds.
func runTest(m *testing.M) int {
// Initialize the configuration and logging systems. Plus anything
// else the web app layer needs.
tests.Init("ASK")
// Initialize MongoDB using the `tests.TestSession` as the name of the
// master session.
if err := db.RegMasterSession(tests.Context, tests.TestSession, cfg.MustURL("MONGO_URI").String(), 0); err != nil {
fmt.Println("Can't register master session: " + err.Error())
return 1
}
db, err := db.NewMGO(tests.Context, tests.TestSession)
if err != nil {
log.Fatalf("Should be able to get a Mongo session : %v", err)
}
defer db.CloseMGO(tests.Context)
// We need the database indexes setup before we can call anything, so do this
// first. This is fairly important, so we want to fail the entire test suite
// if we can't setup the indexes.
if err := submission.EnsureIndexes(tests.Context, db); err != nil {
log.Fatal("Can't ensure the database indexes")
}
return m.Run()
}
示例5: TestNotExists
// TestNotExists validates the ability to load configuration values
// using the OS-level environment variables and panic when something
// is missing.
func TestNotExists(t *testing.T) {
t.Log("Given the need to panic when environment variables are missing.")
{
os.Setenv("MYAPP_PROC_ID", "322")
os.Setenv("MYAPP_SOCKET", "./tmp/sockets.po")
os.Setenv("MYAPP_PORT", "4034")
os.Setenv("MYAPP_FLAG", "true")
cfg.Init("MYAPP")
t.Log("\tWhen given a namspace key to search for that does NOT exist.")
{
shouldPanic(t, "STAMP", func() {
cfg.MustTime("STAMP")
})
shouldPanic(t, "PID", func() {
cfg.MustInt("PID")
})
shouldPanic(t, "DEST", func() {
cfg.MustString("DEST")
})
shouldPanic(t, "ACTIVE", func() {
cfg.MustBool("ACTIVE")
})
shouldPanic(t, "SOCKET_DSN", func() {
cfg.MustURL("SOCKET_DSN")
})
}
}
}
示例6: runTest
// runTest initializes the environment for the tests and allows for
// the proper return code if the test fails or succeeds.
func runTest(m *testing.M) int {
// Initialize MongoDB using the `tests.TestSession` as the name of the
// master session.
if err := db.RegMasterSession(tests.Context, tests.TestSession, cfg.MustURL("MONGO_URI").String(), 0); err != nil {
fmt.Println("Can't register master session: " + err.Error())
return 1
}
// Setup the app for performing tests.
a = routes.API()
// Snatch the mongo session so we can create some test data.
db, err := db.NewMGO(tests.Context, tests.TestSession)
if err != nil {
fmt.Println("Unable to get Mongo session")
return 1
}
defer db.CloseMGO(tests.Context)
if err := loadItems(tests.Context, db); err != nil {
fmt.Println("Could not load items")
return 1
}
defer itemfix.Remove(tests.Context, db, itemPrefix)
if err := loadPatterns(tests.Context, db); err != nil {
fmt.Println("Could not load patterns")
return 1
}
defer patternfix.Remove(tests.Context, db, patternPrefix)
return m.Run()
}
示例7: main
func main() {
app.Init(cfg.EnvProvider{Namespace: Namespace})
// Pull options from the config.
var conn *db.DB
if _, errHost := cfg.String(cfgWebHost); errHost != nil {
xenia.Println("Configuring MongoDB")
mongoURI := cfg.MustURL(cfgMongoURI)
err := db.RegMasterSession("startup", mongoURI.Path, mongoURI.String(), 0)
if err != nil {
xenia.Println("Unable to initialize MongoDB")
os.Exit(1)
}
conn, err = db.NewMGO("startup", mongoURI.Path)
if err != nil {
xenia.Println("Unable to get MongoDB session")
os.Exit(1)
}
defer conn.CloseMGO("startup")
}
xenia.AddCommand(
cmddb.GetCommands(conn),
cmdquery.GetCommands(),
cmdscript.GetCommands(),
cmdregex.GetCommands(),
cmdmask.GetCommands(),
cmdrelationship.GetCommands(),
cmdview.GetCommands(),
)
xenia.Execute()
}
示例8: setup
// setup initializes for each indivdual test.
func setup(t *testing.T) *cayley.Handle {
tests.ResetLog()
store, err := cayleyshelf.New(cfg.MustURL("MONGO_URI").String(), nil)
if err != nil {
t.Fatalf("\t%s\tShould be able to connect to the cayley graph : %s", tests.Failed, err)
}
return store
}
示例9: runTest
// runTest initializes the environment for the tests and allows for
// the proper return code if the test fails or succeeds.
func runTest(m *testing.M) int {
// Initialize MongoDB using the `tests.TestSession` as the name of the
// master session.
if err := db.RegMasterSession(tests.Context, tests.TestSession, cfg.MustURL("MONGO_URI").String(), 0); err != nil {
fmt.Println("Can't register master session: " + err.Error())
return 1
}
return m.Run()
}
示例10: runTest
// runTest initializes the environment for the tests and allows for
// the proper return code if the test fails or succeeds.
func runTest(m *testing.M) int {
// Create stub server for Sponged.
server := setup()
cfg.SetString("SPONGED_URL", server)
mongoURI := cfg.MustURL("MONGO_URI")
// Initialize MongoDB using the `tests.TestSession` as the name of the
// master session.
if err := db.RegMasterSession(tests.Context, tests.TestSession, mongoURI.String(), 0); err != nil {
fmt.Println("Can't register master session: " + err.Error())
return 1
}
a = routes.API()
// Snatch the mongo session so we can create some test data.
db, err := db.NewMGO(tests.Context, tests.TestSession)
if err != nil {
fmt.Println("Unable to get Mongo session")
return 1
}
defer db.CloseMGO(tests.Context)
if err = db.NewCayley(tests.Context, tests.TestSession); err != nil {
fmt.Println("Unable to get Cayley support")
}
store, err := db.GraphHandle(tests.Context)
if err != nil {
fmt.Println("Unable to get Cayley handle")
return 1
}
defer store.Close()
if err := tstdata.Generate(db); err != nil {
fmt.Println("Could not generate test data.")
return 1
}
defer tstdata.Drop(db)
if err := loadItems("context", db, store); err != nil {
fmt.Println("Could not import items")
return 1
}
defer unloadItems("context", db, store)
return m.Run()
}
示例11: API
// API returns a handler for a set of routes.
func API() http.Handler {
mongoURI := cfg.MustURL(cfgMongoURI)
// The web framework middleware for Mongo is using the name of the
// database as the name of the master session by convention. So use
// cfg.DB as the second argument when creating the master session.
if err := db.RegMasterSession("startup", mongoURI.Path, mongoURI.String(), 25*time.Second); err != nil {
log.Error("startup", "Init", err, "Initializing MongoDB")
os.Exit(1)
}
w := web.New(logm.Midware, errorm.Midware)
publicKey, err := cfg.String(cfgAuthPublicKey)
if err != nil || publicKey == "" {
log.User("startup", "Init", "%s is missing, internal authentication is disabled", cfgAuthPublicKey)
}
// If the public key is provided then add the auth middleware or fail using
// the provided public key.
if publicKey != "" {
log.Dev("startup", "Init", "Initializing Auth")
authm, err := authm.Midware(publicKey, authm.MidwareOpts{})
if err != nil {
log.Error("startup", "Init", err, "Initializing Auth")
os.Exit(1)
}
// Apply the authentication middleware on top of the application as the
// first middleware.
w.Use(authm)
}
// Add the Mongo and Cayley middlewares possibly after the auth middleware.
w.Use(mongo.Midware(mongoURI), cayley.Midware(mongoURI))
if cors, err := cfg.Bool(cfgEnableCORS); err == nil && cors {
log.Dev("startup", "Init", "Initializing CORS : CORS Enabled")
w.Use(w.CORS())
} else {
log.Dev("startup", "Init", "CORS Disabled")
}
log.Dev("startup", "Init", "Initalizing routes")
routes(w)
return w
}
示例12: runTest
// runTest initializes the environment for the tests and allows for
// the proper return code if the test fails or succeeds.
func runTest(m *testing.M) int {
// Initialize the configuration and logging systems. Plus anything
// else the web app layer needs.
tests.Init("XENIA")
// Initialize MongoDB using the `tests.TestSession` as the name of the
// master session.
if err := db.RegMasterSession(tests.Context, tests.TestSession, cfg.MustURL("MONGO_URI").String(), 0); err != nil {
fmt.Println("Can't register master session: " + err.Error())
return 1
}
return m.Run()
}
示例13: routes
// routes manages the handling of the API endpoints.
func routes(w *web.Web) {
w.Handle("GET", "/v1/version", handlers.Version.List)
w.Handle("GET", "/v1/script", handlers.Script.List)
w.Handle("PUT", "/v1/script", handlers.Script.Upsert)
w.Handle("GET", "/v1/script/:name", handlers.Script.Retrieve)
w.Handle("DELETE", "/v1/script/:name", handlers.Script.Delete)
w.Handle("GET", "/v1/query", handlers.Query.List)
w.Handle("PUT", "/v1/query", handlers.Query.Upsert)
w.Handle("GET", "/v1/query/:name", handlers.Query.Retrieve)
w.Handle("DELETE", "/v1/query/:name", handlers.Query.Delete)
w.Handle("PUT", "/v1/index/:name", handlers.Query.EnsureIndexes)
w.Handle("GET", "/v1/regex", handlers.Regex.List)
w.Handle("PUT", "/v1/regex", handlers.Regex.Upsert)
w.Handle("GET", "/v1/regex/:name", handlers.Regex.Retrieve)
w.Handle("DELETE", "/v1/regex/:name", handlers.Regex.Delete)
w.Handle("GET", "/v1/mask", handlers.Mask.List)
w.Handle("PUT", "/v1/mask", handlers.Mask.Upsert)
w.Handle("GET", "/v1/mask/:collection/:field", handlers.Mask.Retrieve)
w.Handle("GET", "/v1/mask/:collection", handlers.Mask.Retrieve)
w.Handle("DELETE", "/v1/mask/:collection/:field", handlers.Mask.Delete)
w.Handle("POST", "/v1/exec", handlers.Exec.Custom)
w.Handle("GET", "/v1/exec/:name", handlers.Exec.Name)
// Create the Cayley middleware which will only be binded to specific
// endpoints.
cayleym := cayley.Midware(cfg.MustURL(cfgMongoURI))
// These endpoints require Cayley, we will add the middleware onto the routes.
w.Handle("GET", "/v1/exec/:name/view/:view/:item", handlers.Exec.NameOnView, cayleym)
w.Handle("POST", "/v1/exec/view/:view/:item", handlers.Exec.CustomOnView, cayleym)
w.Handle("GET", "/v1/relationship", handlers.Relationship.List)
w.Handle("PUT", "/v1/relationship", handlers.Relationship.Upsert)
w.Handle("GET", "/v1/relationship/:predicate", handlers.Relationship.Retrieve)
w.Handle("DELETE", "/v1/relationship/:predicate", handlers.Relationship.Delete)
w.Handle("GET", "/v1/view", handlers.View.List)
w.Handle("PUT", "/v1/view", handlers.View.Upsert)
w.Handle("GET", "/v1/view/:name", handlers.View.Retrieve)
w.Handle("DELETE", "/v1/view/:name", handlers.View.Delete)
}
示例14: API
// API returns a handler for a set of routes.
func API() http.Handler {
mongoURI := cfg.MustURL(cfgMongoURI)
// The web framework middleware for Mongo is using the name of the
// database as the name of the master session by convention. So use
// cfg.DB as the second argument when creating the master session.
if err := db.RegMasterSession("startup", mongoURI.Path, mongoURI.String(), 25*time.Second); err != nil {
log.Error("startup", "Init", err, "Initializing MongoDB")
os.Exit(1)
}
// Ensure that the database indexes are setup on the underlying MongoDB
// database.
if err := ensureDBIndexes(mongoURI); err != nil {
log.Error("startup", "Init", err, "Initializing DB Indexes")
os.Exit(1)
}
w := web.New(logm.Midware, errorm.Midware, mongo.Midware(mongoURI))
// Load in the recaptcha secret from the config.
if recaptcha, err := cfg.String(cfgRecaptchaSecret); err == nil && recaptcha != "" {
w.Ctx["recaptcha"] = recaptcha
log.Dev("startup", "Init", "Recaptcha Enabled")
} else {
log.Dev("startup", "Init", "%s is missing, recaptcha is disabled", cfgRecaptchaSecret)
}
if cors, err := cfg.Bool(cfgEnableCORS); err == nil && cors {
log.Dev("startup", "Init", "Initializing CORS : CORS Enabled")
w.Use(w.CORS())
} else {
log.Dev("startup", "Init", "CORS Disabled")
}
log.Dev("startup", "Init", "Initalizing routes")
routes(w)
return w
}
示例15: runTest
// runTest initializes the environment for the tests and allows for
// the proper return code if the test fails or succeeds.
func runTest(m *testing.M) int {
// Initialize MongoDB using the `tests.TestSession` as the name of the
// master session.
if err := db.RegMasterSession(tests.Context, tests.TestSession, cfg.MustURL("MONGO_URI").String(), 0); err != nil {
fmt.Println("Can't register master session: " + err.Error())
return 1
}
db, err := db.NewMGO(tests.Context, tests.TestSession)
if err != nil {
fmt.Println("Can't get mongo session: " + err.Error())
return 1
}
defer db.CloseMGO(tests.Context)
loadPatterns("context", db)
defer patternfix.Remove("context", db, patternPrefix)
defer itemfix.Remove("context", db, itemPrefix)
return m.Run()
}