本文整理汇总了Golang中github.com/Sirupsen/logrus.Panic函数的典型用法代码示例。如果您正苦于以下问题:Golang Panic函数的具体用法?Golang Panic怎么用?Golang Panic使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Panic函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: configureAdvanced
func (riakNode *RiakNode) configureAdvanced(cepmdPort int) {
data, err := Asset("data/advanced.config")
if err != nil {
log.Panic("Got error", err)
}
tmpl, err := template.New("advanced").Parse(string(data))
if err != nil {
log.Panic(err)
}
// Populate template data from the MesosTask
vars := advancedTemplateData{}
vars.CEPMDPort = cepmdPort
file, err := os.OpenFile("riak/riak/etc/advanced.config", os.O_TRUNC|os.O_CREATE|os.O_RDWR, 0664)
defer file.Close()
if err != nil {
log.Panic("Unable to open file: ", err)
}
err = tmpl.Execute(file, vars)
if err != nil {
log.Panic("Got error", err)
}
}
示例2: run
func run(version, cmd string, cmdArgs []string) *os.ProcessState {
path := os.Getenv("PATH")
cwd, err := os.Getwd()
if err != nil {
log.Panic(err)
}
goroot := filepath.Join(envPath, version, "go")
os.Setenv("GO15VENDOREXPERIMENT", "1")
os.Setenv("GOPATH", goPath)
log.Println("GOPATH", goPath)
os.Setenv("GOROOT", goroot)
log.Println("GOROOT", goroot)
// Sometimes we want to use tools from local install
os.Setenv("PATH", goPath+"/bin:"+goroot+"/bin:"+path)
pa := os.ProcAttr{
Files: []*os.File{os.Stdin, os.Stdout, os.Stderr},
Dir: cwd,
}
proc, err := os.StartProcess(cmd, cmdArgs, &pa)
if err != nil {
log.Panic(err)
}
state, err := proc.Wait()
if err != nil {
log.Panic(err)
}
return state
}
示例3: configureAdvanced
func (re *RiakExplorer) configureAdvanced(cepmdPort int) {
data, err := Asset("advanced.config")
if err != nil {
log.Panic("Got error", err)
}
tmpl, err := template.New("advanced").Parse(string(data))
if err != nil {
log.Panic(err)
}
// Populate template data from the MesosTask
vars := advancedTemplateData{}
vars.CEPMDPort = cepmdPort
configpath := filepath.Join(".", "riak_explorer", "riak_explorer", "etc", "advanced.config")
file, err := os.OpenFile(configpath, os.O_TRUNC|os.O_CREATE|os.O_RDWR, 0)
defer file.Close()
if err != nil {
log.Panic("Unable to open file: ", err)
}
err = tmpl.Execute(file, vars)
if err != nil {
log.Panic("Got error", err)
}
}
示例4: configureAdvanced
func (riakNode *RiakNode) configureAdvanced(cepmdPort int) {
fetchURI := fmt.Sprintf("%s/api/v1/clusters/%s/advancedConfig", riakNode.taskData.URI, riakNode.taskData.ClusterName)
resp, err := http.Get(fetchURI)
if err != nil {
log.Error("Unable to fetch advanced config: ", err)
}
advancedConfig, err := ioutil.ReadAll(resp.Body)
resp.Body.Close()
if err != nil {
log.Error("Unable to fetch advanced config: ", err)
}
tmpl, err := template.New("advanced").Parse(string(advancedConfig))
if err != nil {
log.Panic(err)
}
// Populate template data from the MesosTask
vars := advancedTemplateData{}
vars.CEPMDPort = cepmdPort
file, err := os.OpenFile("root/riak/etc/advanced.config", os.O_TRUNC|os.O_CREATE|os.O_RDWR, 0664)
defer file.Close()
if err != nil {
log.Panic("Unable to open file: ", err)
}
err = tmpl.Execute(file, vars)
if err != nil {
log.Panic("Got error", err)
}
}
示例5: writePacketLength
func writePacketLength(dst []byte) error {
var LENGTH_OFFSET uint = 13
var LENGTH_HEADER uint = 15
var MAX_LENGTH uint = 0xFFFF
if uint(len(dst)) < LENGTH_HEADER {
log.Panic("Tried to set packet length to short buffer")
}
if uint(len(dst)) > MAX_LENGTH {
log.Panic("Tried to set to big a packet length")
}
log.Println("Length of packet is:", len(dst))
var length uint = uint(len(dst)) - (LENGTH_OFFSET + 7)
log.Println("Setting packet length to:", length)
l := make([]byte, 2)
binary.LittleEndian.PutUint16(l, uint16(length))
i := LENGTH_OFFSET
dst[i] = l[0]
i++
dst[i] = l[1]
return nil
}
示例6: configureRiak
func (riakNode *RiakNode) configureRiak(ports chan int64) templateData {
data, err := Asset("data/riak.conf")
if err != nil {
log.Panic("Got error", err)
}
tmpl, err := template.New("test").Parse(string(data))
if err != nil {
log.Panic(err)
}
// Populate template data from the MesosTask
vars := templateData{}
vars.FullyQualifiedNodeName = riakNode.taskData.FullyQualifiedNodeName
vars.HTTPPort = <-ports
vars.PBPort = <-ports
vars.HandoffPort = <-ports
vars.DisterlPort = <-ports
file, err := os.OpenFile("riak/riak/etc/riak.conf", os.O_TRUNC|os.O_CREATE|os.O_RDWR, 0664)
defer file.Close()
if err != nil {
log.Panic("Unable to open file: ", err)
}
err = tmpl.Execute(file, vars)
if err != nil {
log.Panic("Got error", err)
}
return vars
}
示例7: init
func init() {
dbUrl := os.Getenv("DATABASE_URL")
if dbUrl == "" {
log.Panic("Missing required environment variable 'DATABASE_URL'.")
}
db, err := sql.Open("postgres", dbUrl)
fmt.Println("dbUrl", dbUrl)
checkErr(err)
if nil != err {
log.WithFields(log.Fields{
"error": err,
}).Fatal("Database connection error")
log.Panic("failed to open db")
}
dbmap = &gorp.DbMap{
Db: db,
Dialect: gorp.PostgresDialect{},
}
if os.Getenv("DEBUG") == "true" {
dbmap.TraceOn("[gorp]", stdlog.New(os.Stdout, "authentication:", stdlog.Lmicroseconds))
}
t := dbmap.AddTableWithName(User{}, "users").SetKeys(true, "Id")
log.Info(t)
t = dbmap.AddTableWithName(Event{}, "events").SetKeys(true, "Id")
log.Info(t)
t = dbmap.AddTableWithName(Attendance{}, "attendance")
log.Info(t)
mydb = db
}
示例8: Run
func Run() {
sinceID, err := store.SinceID()
if err != nil {
log.Panic(err)
}
store.Expire()
statuses, err := twitter.GetListStatuses(sinceID)
if err != nil {
log.Panic(err)
}
for index, status := range statuses {
if index == 0 {
store.SetSinceID(status.ID)
}
for _, url := range status.Entities.URLs {
link, err := metadata.ParseURL(url.ExpandedURL)
if err != nil {
log.Error(err)
continue
}
store.Add(link)
}
}
}
示例9: configure
func (re *RiakExplorer) configure(port int64, nodename string) {
data, err := Asset("riak_explorer.conf")
if err != nil {
log.Panic("Got error", err)
}
tmpl, err := template.New("test").Parse(string(data))
if err != nil {
log.Panic(err)
}
// Populate template data from the MesosTask
vars := templateData{}
vars.NodeName = nodename
vars.HTTPPort = port
configpath := filepath.Join(".", "riak_explorer", "riak_explorer", "etc", "riak_explorer.conf")
file, err := os.OpenFile(configpath, os.O_TRUNC|os.O_CREATE|os.O_RDWR, 0)
defer file.Close()
if err != nil {
log.Panic("Unable to open file: ", err)
}
err = tmpl.Execute(file, vars)
if err != nil {
log.Panic("Got error", err)
}
}
示例10: main
func main() {
var (
laddr *net.UDPAddr
mcaddr *net.UDPAddr
conn *net.UDPConn
lconn *net.UDPConn
err error
)
laddr, err = net.ResolveUDPAddr("udp", ":0")
if err != nil {
logrus.Panicf("Error resolving UDP address with %v", err)
}
mcaddr, err = net.ResolveUDPAddr("udp", "239.255.2.122:1234")
if err != nil {
logrus.Panicf("Error resolving UDP address with %v", err)
}
conn, err = net.ListenMulticastUDP("udp", nil, mcaddr)
if err != nil {
logrus.Panic(err)
}
lconn, err = net.ListenUDP("udp", laddr)
if err != nil {
logrus.Panic(err)
}
go listen(conn)
go write(conn, lconn, mcaddr)
}
示例11: GenerateDefaultTLS
// GenerateDefaultTLS will generate a certificate and a private key, on-the-fly
// This certificate will not be persistant (until you save it yourself)
// This is made by design to generate a new certificate at each server start, if you
// don't provide one yourself
func GenerateDefaultTLS(certPath string, keyPath string) (cert []byte, key []byte) {
log.Info("Generating TLS certificate and key")
rootName := "itsyou.online"
priv, err := ecdsa.GenerateKey(elliptic.P384(), rand.Reader)
if err != nil {
log.Panic("Failed to generate private key: ", err)
}
notBefore := time.Now()
notAfter := notBefore.Add(4 * 365 * 24 * time.Hour) // 4 years
serialNumberLimit := new(big.Int).Lsh(big.NewInt(1), 128)
serialNumber, err := rand.Int(rand.Reader, serialNumberLimit)
if err != nil {
log.Panic("Failed to generate serial number: ", err)
}
template := x509.Certificate{
SerialNumber: serialNumber,
Subject: pkix.Name{
Country: []string{"Belgium"},
Locality: []string{"Lochristi"},
Organization: []string{"It's You Online"},
CommonName: rootName,
},
NotBefore: notBefore,
NotAfter: notAfter,
KeyUsage: x509.KeyUsageKeyEncipherment | x509.KeyUsageDigitalSignature,
ExtKeyUsage: []x509.ExtKeyUsage{x509.ExtKeyUsageServerAuth},
BasicConstraintsValid: true,
DNSNames: []string{rootName},
}
derBytes, err := x509.CreateCertificate(rand.Reader, &template, &template, &priv.PublicKey, priv)
if err != nil {
log.Panic("Failed to create certificate: ", err)
}
// Certificates output (in memory)
var certOut, keyOut bytes.Buffer
pem.Encode(&certOut, &pem.Block{Type: "CERTIFICATE", Bytes: derBytes})
b, err := x509.MarshalECPrivateKey(priv)
if err != nil {
log.Panic("Unable to marshal ECDSA private key: ", err)
}
pemUnmarsh := pem.Block{Type: "EC PRIVATE KEY", Bytes: b}
pem.Encode(&keyOut, &pemUnmarsh)
return certOut.Bytes(), keyOut.Bytes()
}
示例12: PrepareHTTPS
func PrepareHTTPS(s *http.Server, cert string, key string, skipDev bool) error {
// Checking for TLS default keys
var certBytes, keyBytes []byte
devCert := "devcert/cert.pem"
devKey := "devcert/key.pem"
// If only a single argument is set
if (cert == "" || key == "") && (cert != "" || key != "") {
log.Panic("You cannot specify only key or certificate")
}
// Using default certificate
if cert == "" && !skipDev {
if _, err := os.Stat(devCert); err == nil {
if _, err := os.Stat(devKey); err == nil {
log.Warning("===============================================================================")
log.Warning("This instance will use development certificates, don't use them in production !")
log.Warning("===============================================================================")
cert = devCert
key = devKey
} else {
log.Debug("No devcert key found: ", devKey)
}
} else {
log.Debug("No devcert certificate found: ", devCert)
}
}
if _, err := os.Stat(cert); err != nil {
if _, err := os.Stat(key); err != nil {
certBytes, keyBytes = GenerateDefaultTLS(cert, key)
}
} else {
log.Info("Loading TLS Certificate: ", cert)
log.Info("Loading TLS Private key: ", key)
certBytes, err = ioutil.ReadFile(cert)
keyBytes, err = ioutil.ReadFile(key)
}
certifs, err := tls.X509KeyPair(certBytes, keyBytes)
if err != nil {
log.Panic("Cannot parse certificates")
}
s.TLSConfig = &tls.Config{
Certificates: []tls.Certificate{certifs},
}
return nil
}
示例13: main
func main() {
//TODO os.Getenv("DOMAIN")
configureSocial()
// Load all configuration
appCfg = &AppConfig{}
mgoCfg := &MgoConfig{}
natsCfg := &NatsConfig{}
loadConfiguration(appCfg, mgoCfg, natsCfg)
log.Infoln("Initializing NatsMailClient")
initMail()
var mailErr error
mailClient, mailErr = client.NewNatsMailClient(natsCfg.Endpoint)
if mailErr != nil {
log.Errorf("Cannot initialize mail client: %s", mailErr.Error())
}
//Mongo configuration
log.Infoln("Loading configuration of MongoDB")
mgoStorage := auth.NewMgoStorage()
mgoStorage.ConnectionString = mgoCfg.URI
mgoStorage.Database = mgoCfg.DB
err := mgoStorage.OpenSession()
if err != nil {
log.Panic(err)
}
log.Infoln("Initializing auth provider")
mgoAuthProvider := auth.NewAuthProvider(mgoStorage)
authProvider = mgoAuthProvider
passManager = mgoAuthProvider
log.Infoln("Initializing reverse proxy")
log.Infoln("Registering handlers")
//Handle login and register
clientConn, _ := nats.Connect(natsCfg.Endpoint)
defer clientConn.Close()
mux, natsErr := natsproxy.NewNatsClient(clientConn)
if natsErr != nil {
log.Panic("Cannot initialize NATS client")
}
mux.GET("/activate/:activateToken", activateHandler)
mux.POST("/login", loginHandler)
mux.POST("/register", registerHandler)
mux.POST("/requestpasswordreset", requestPasswordResetHandler)
mux.POST("/resetpassword/:resettoken", passwordResetHandler)
// mux.Get("/auth/{provider}/callback", handleSocialLogin)
// mux.Get("/auth/{provider}", gothic.BeginAuthHandler)
//else handle via proxy
sig := make(chan os.Signal, 1)
signal.Notify(sig, syscall.SIGINT, syscall.SIGTERM)
fmt.Println("Press Ctrl+C for exit.")
<-sig
}
示例14: GetPort
func (c *CEPM) GetPort() int {
_, strPort, err := net.SplitHostPort(c.ln.Addr().String())
if err != nil {
log.Panic(err)
}
port, err := strconv.Atoi(strPort)
if err != nil {
log.Panic(err)
}
return port
}
示例15: NewLogSegment
// Constructor
func NewLogSegment(baseSeg Segment, start uint, len uint) LogSegment {
baseLen := baseSeg.Len()
if start >= baseLen {
log.Panic("invalid segment start")
}
if start+len > baseLen {
log.Panic("invalid segment length")
}
return LogSegment{baseSeg, start, len}
}