本文整理汇总了Golang中github.com/couchbaselabs/logg.LogPanic函数的典型用法代码示例。如果您正苦于以下问题:Golang LogPanic函数的具体用法?Golang LogPanic怎么用?Golang LogPanic使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了LogPanic函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: init
func init() {
//set logging
logg.LogKeys[TagError] = true
logg.LogKeys[TagDiff] = true
if DEBUG == false {
logg.LogKeys[TagLog] = true
}
kingpin.Parse()
if *configFileName == "" {
kingpin.Errorf("Config file name missing")
return
}
configFile, err := os.Open(*configFileName)
if err != nil {
logg.LogPanic("Unable to open file: %v. Err: %v", *configFileName, err.Error())
return
}
defer configFile.Close()
configReader := bufio.NewReader(configFile)
err = parseConfigFile(configReader)
if err != nil {
logg.LogPanic("Erro parsing the config file: %v", err)
}
}
示例2: authenticate
//authenticate uses a custom service to authenticate against a credentials repository like Active Directory
//and returns a session from sync gateway
func authenticate() AuthResponse {
request, err := http.NewRequest("POST", authConfig.ServerURL, bytes.NewReader([]byte("{\"username\": \""+authConfig.Username+"\", \"password\": \""+authConfig.Password+"\"}")))
if err != nil {
logg.LogPanic("Error creating request: %v", err)
}
logRequest(request)
response, err := globalHTTP.Do(request)
if err != nil {
logg.LogPanic("Error authenticating: %v", err)
}
defer response.Body.Close()
authResponse := AuthResponse{}
document, err := ioutil.ReadAll(response.Body)
if err != nil {
logg.LogPanic("Error reading contents: %v", err)
}
json.Unmarshal(document, &authResponse)
return authResponse
}
示例3: main
func main() {
var preprocessor string
flagFunc := func() {
flag.StringVar(
&preprocessor,
"preprocessor",
"identity",
"The preprocessor to use, eg, stroke-width-transform",
)
}
rabbitConfig := ocrworker.DefaultConfigFlagsOverride(flagFunc)
// inifinite loop, since sometimes worker <-> rabbitmq connection
// gets broken. see https://github.com/tleyden/open-ocr/issues/4
for {
logg.LogTo("PREPROCESSOR_WORKER", "Creating new Preprocessor Worker")
preprocessorWorker, err := ocrworker.NewPreprocessorRpcWorker(
rabbitConfig,
preprocessor,
)
if err != nil {
logg.LogPanic("Could not create rpc worker: %v", err)
}
preprocessorWorker.Run()
// this happens when connection is closed
err = <-preprocessorWorker.Done
logg.LogError(fmt.Errorf("Preprocessor Worker failed with error: %v", err))
}
}
示例4: InitDbConnection
func (game *Game) InitDbConnection() {
db, error := couch.Connect(SERVER_URL)
if error != nil {
logg.LogPanic("Error connecting to %v: %v", SERVER_URL, error)
}
game.db = db
}
示例5: setAuth
func setAuth(request *http.Request) {
if authConfig.Username != "" && authConfig.Password != "" {
if authConfig.SimpleAuth {
request.SetBasicAuth(authConfig.Username, authConfig.Password)
} else {
session := authenticate()
layout := "2006-01-02T15:04:05Z07:00"
expire, err := time.Parse(layout, session.Expires)
if err != nil {
logg.LogPanic("Error parsing time: %v", err)
}
rawCookie := []string{session.CookieName + "=" + session.SessionID}
maxAge := 0
secure := true
httpOnly := true
path := "/"
cookie := http.Cookie{session.CookieName, session.SessionID, path, config.SyncURL, expire, expire.Format(time.UnixDate), maxAge, secure, httpOnly, rawCookie[0], rawCookie}
request.AddCookie(&cookie)
}
}
}
示例6: NewUuid
func NewUuid() string {
u4, err := uuid.NewV4()
if err != nil {
logg.LogPanic("Error generating uuid", err)
}
return fmt.Sprintf("%s", u4)
}
示例7: FollowChangesFeed
// Follow changes feed. This will typically be run in its own goroutine.
func (c ChangesListener) FollowChangesFeed() {
logg.LogTo("CHANGES", "going to follow changes feed")
var since interface{}
handleChange := func(reader io.Reader) interface{} {
logg.LogTo("CHANGES", "handleChange() callback called")
changes, err := decodeChanges(reader)
if err != nil {
// it's very common for this to timeout while waiting for new changes.
// since we want to follow the changes feed forever, just log an error
logg.LogTo("CHANGES", "%T decoding changes: %v.", err, err)
return since
}
c.processChanges(changes)
since = changes.LastSequence
logg.LogTo("CHANGES", "returning since: %v", since)
return since
}
options := map[string]interface{}{}
options["feed"] = "longpoll"
logg.LogTo("CHANGES", "Following changes feed: %+v.", options)
// this will block until the handleChange callback returns nil
c.Database.Changes(handleChange, options)
logg.LogPanic("Changes listener died -- this should never happen")
}
示例8: generateOffspring
func (pt *PopulationTrainer) generateOffspring(population []EvaluatedCortex) (withOffspring []EvaluatedCortex) {
withOffspring = make([]EvaluatedCortex, 0)
withOffspring = append(withOffspring, population...)
for _, evaldCortex := range population {
cortex := evaldCortex.Cortex
offspringCortex := cortex.Copy()
offspringNodeIdStr := fmt.Sprintf("cortex-%s", ng.NewUuid())
offspringCortex.NodeId = ng.NewCortexId(offspringNodeIdStr)
succeeded, _ := pt.CortexMutator(offspringCortex)
if !succeeded {
logg.LogPanic("Unable to mutate cortex: %v", offspringCortex)
}
evaldCortexOffspring := EvaluatedCortex{
Cortex: offspringCortex,
ParentId: cortex.NodeId.UUID,
CreatedInGeneration: pt.CurrentGeneration,
Fitness: 0.0,
}
withOffspring = append(withOffspring, evaldCortexOffspring)
}
return
}
示例9: DbConnection
// Connect to db based on url stored in config, or panic if not able to connect
func (c Configuration) DbConnection() couch.Database {
db, err := couch.Connect(c.DbUrl)
if err != nil {
err = errors.New(fmt.Sprintf("Error %v | dbUrl: %v", err, c.DbUrl))
logg.LogPanic("%v", err)
}
return db
}
示例10: unmarshalCortex
func unmarshalCortex(pathToCortex string) *ng.Cortex {
cortex, err := ng.NewCortexFromJSONFile(pathToCortex)
if err != nil {
logg.LogPanic("Error reading cortex from: %v. Err: %v", pathToCortex, err)
}
return cortex
}
示例11: makeHandler
func makeHandler(method handlerMethod) http.Handler {
return http.HandlerFunc(func(r http.ResponseWriter, rq *http.Request) {
h := newHandler(r, rq)
err := h.invoke(method)
if err != nil {
logg.LogPanic("Error creating http handler: %v", err)
}
})
}
示例12: parseConfigFile
func parseConfigFile(r io.Reader) {
config = Config{}
decoder := json.NewDecoder(r)
if err := decoder.Decode(&config); err != nil {
logg.LogPanic("Error parsing config file: %v", err)
}
}
示例13: DisabledTestOcrHttpHandlerIntegration
// This test assumes that rabbit mq is running
func DisabledTestOcrHttpHandlerIntegration(t *testing.T) {
rabbitConfig := rabbitConfigForTests()
err := spawnOcrWorker(rabbitConfig)
if err != nil {
logg.LogPanic("Could not spawn ocr worker")
}
// add a handler to serve up an image from the filesystem.
http.HandleFunc("/img", func(w http.ResponseWriter, r *http.Request) {
http.ServeFile(w, r, "refactoring.png")
})
http.Handle("/ocr", NewOcrHttpHandler(rabbitConfig))
go http.ListenAndServe(":8081", nil)
logg.LogTo("TEST", "test1")
ocrRequest := OcrRequest{
ImgUrl: "http://localhost:8081/img",
EngineType: ENGINE_MOCK,
}
jsonBytes, err := json.Marshal(ocrRequest)
if err != nil {
logg.LogPanic("Could not marshal OcrRequest")
}
reader := bytes.NewReader(jsonBytes)
resp, err := http.Post("http://localhost:8081/ocr", "application/json", reader)
assert.True(t, err == nil)
logg.LogTo("TEST", "resp: %v", resp)
// connect to it via http client
logg.LogTo("TEST", "Sleep for 60s")
time.Sleep(time.Second * 60)
// make sure get expected result
assert.True(t, true)
}
示例14: startWebServer
func startWebServer() {
sock, err := net.Listen("tcp", ":"+fmt.Sprintf("%d", webPort))
if err != nil {
logg.LogPanic("Error starting web server : %v", err)
}
go func() {
fmt.Println("HTTP now available at port ", webPort)
http.Serve(sock, nil)
}()
}
示例15: confirmDeliveryWorker
func confirmDeliveryWorker(ack, nack chan uint64) {
logg.LogTo("OCR_WORKER", "awaiting delivery confirmation ...")
select {
case tag := <-ack:
logg.LogTo("OCR_WORKER", "confirmed delivery, tag: %v", tag)
case tag := <-nack:
logg.LogTo("OCR_WORKER", "failed to confirm delivery: %v", tag)
case <-time.After(RPC_RESPONSE_TIMEOUT):
// this is bad, the worker will probably be dsyfunctional
// at this point, so panic
logg.LogPanic("timeout trying to confirm delivery")
}
}