本文整理汇总了Golang中log.Panic函数的典型用法代码示例。如果您正苦于以下问题:Golang Panic函数的具体用法?Golang Panic怎么用?Golang Panic使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Panic函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: upload
func upload(res http.ResponseWriter, req *http.Request) {
defer logException(res, req)
if req.Method == "POST" {
file, _, err := req.FormFile("pic")
if err != nil {
log.Panic(err)
}
defer file.Close()
wr := &manager.MongoWriter{}
image, err := asciiEncoder.DecodeImage(file)
if err != nil {
log.Panic(err)
}
err = asciiEncoder.Asciify(image, wr)
if err != nil {
log.Panic(err)
}
uri := mongoArtManager.Save(wr)
http.Redirect(res, req, "/art/"+uri, 302)
}
}
示例2: SignDeterministic
//generate signature in repeatable way
func SignDeterministic(msg []byte, seckey []byte, nonce_seed []byte) []byte {
nonce := SumSHA256(nonce_seed) //deterministicly generate nonce
var sig []byte = make([]byte, 65)
var recid C.int
var msg_ptr *C.uchar = (*C.uchar)(unsafe.Pointer(&msg[0]))
var seckey_ptr *C.uchar = (*C.uchar)(unsafe.Pointer(&seckey[0]))
var nonce_ptr *C.uchar = (*C.uchar)(unsafe.Pointer(&nonce[0]))
var sig_ptr *C.uchar = (*C.uchar)(unsafe.Pointer(&sig[0]))
if C.secp256k1_ecdsa_seckey_verify(seckey_ptr) != C.int(1) {
log.Panic("Invalid secret key")
}
ret := C.secp256k1_ecdsa_sign_compact(
msg_ptr, C.int(len(msg)),
sig_ptr,
seckey_ptr,
nonce_ptr,
&recid)
sig[64] = byte(int(recid))
if int(recid) > 4 {
log.Panic()
}
if ret != 1 {
return SignDeterministic(msg, seckey, nonce_seed) //nonce invalid,retry
}
return sig
}
示例3: CreateGenesisBlockInit
func (self *Visor) CreateGenesisBlockInit() (SignedBlock, error) {
self.GenesisPreconditions()
if len(self.Blockchain.Blocks) != 0 || len(self.blockSigs.Sigs) != 0 {
log.Panic("Blockchain already has genesis")
}
if self.Config.BlockchainPubkey != cipher.PubKeyFromSecKey(self.Config.BlockchainSeckey) {
log.Panicf("Cannot create genesis block. Invalid secret key for pubkey")
}
gb := self.Blockchain.CreateGenesisBlock(self.Config.GenesisAddress,
self.Config.GenesisTimestamp, self.Config.GenesisCoinVolume)
sb := self.SignBlock(gb)
if err := self.verifySignedBlock(&sb); err != nil {
log.Panic("Signed a fresh genesis block, but its invalid: %v", err)
}
self.blockSigs.record(&sb)
log.Printf("New Genesis:")
log.Printf("genesis_time= %v", sb.Block.Head.Time)
log.Printf("genesis_address= %v", self.Config.GenesisAddress.String())
log.Printf("genesis_signature= %v", sb.Sig.Hex())
return sb, nil
}
示例4: print
func (p *Pool) print(first bool) bool {
var out string
if !first {
coords, err := getCursorPos()
if err != nil {
log.Panic(err)
}
coords.Y -= int16(len(p.bars))
coords.X = 0
err = setCursorPos(coords)
if err != nil {
log.Panic(err)
}
}
isFinished := true
for _, bar := range p.bars {
if !bar.isFinish {
isFinished = false
}
bar.Update()
out += fmt.Sprintf("\r%s\n", bar.String())
}
fmt.Print(out)
return isFinished
}
示例5: main
func main() {
jenkins_address := os.Getenv("JENKINS_URL")
listen_address := os.Getenv("LISTEN_ADDRESS")
if listen_address == "" {
listen_address = "[::]:8080"
}
if jenkins_address == "" {
log.Fatalln("Use environment variables JENKINS_URL and LISTEN_ADDRESS (default \"[::]:8080\")")
}
remote, err := url.Parse(jenkins_address)
if err != nil {
log.Panic(err)
}
proxy := httputil.NewSingleHostReverseProxy(remote)
http.HandleFunc("/", handler(proxy))
log.Println("jenkins-authentication-proxy", version, "starting")
log.Println("Authentication endpoint:", planio_url)
err = http.ListenAndServe(listen_address, nil)
if err != nil {
log.Panic(err)
}
}
示例6: loadBlockchain
// Loads a blockchain but subdues errors into the logger, or panics.
// If no blockchain is found, it creates a new empty one
func loadBlockchain(filename string, genAddr coin.Address) *coin.Blockchain {
bc := &coin.Blockchain{}
created := false
if filename != "" {
var err error
bc, err = LoadBlockchain(filename)
if err == nil {
if len(bc.Blocks) == 0 {
log.Panic("Loaded empty blockchain")
}
loadedGenAddr := bc.Blocks[0].Body.Transactions[0].Out[0].Address
if loadedGenAddr != genAddr {
log.Panic("Configured genesis address does not match the " +
"address in the blockchain")
}
created = true
} else {
if os.IsNotExist(err) {
logger.Info("No blockchain file, will create a new blockchain")
} else {
log.Panicf("Failed to load blockchain file \"%s\": %v",
filename, err)
}
}
}
if !created {
bc = coin.NewBlockchain()
}
return bc
}
示例7: main
func main() {
//log.SetLevel(log.DebugLevel)
// Create a new client
client := client.NewXenAPIClient("127.0.0.1", "username", "password")
// Login, this will create a session that is used by all other methods
err := client.Login()
if err != nil {
log.Panic(err)
}
// Fetch a list of all VMs, unfortunaly this will return templates and the domain controller as well
vms, err := client.GetVMs()
if err != nil {
log.Panic(err)
}
// Loop thru all VMs
for _, vm := range vms {
// Fetch information about this vm. This method will also return a list with all available records
vm.GetRecord()
// Ignore all that is not a VM (templates and domain controller)
if !vm.IsVM {
continue
}
// Print out information about the VM
fmt.Printf("%s (%s) - %s\n", vm.Name, vm.PowerState, vm.Description)
}
}
示例8: initDataBase
func initDataBase() *sql.DB {
db, err := sql.Open("sqlite3", "./sites.db")
if err != nil {
log.Fatal(err)
}
defer db.Close()
sqlStmt := `
DELETE FROM sites;
DROP TABLE sites;
`
db.Exec(sqlStmt)
if err != nil {
log.Panic("%q: %s\n", err, sqlStmt)
os.Exit(1)
}
sqlStmt = `
CREATE TABLE sites (domain TEXT NOT NULL PRIMARY KEY, code INTEGER);
`
_, err = db.Exec(sqlStmt)
if err != nil {
log.Panic("%q: %s\n", err, sqlStmt)
os.Exit(1)
}
return db
}
示例9: make_window
func make_window(w, h int, title string) func() {
// Required to make sure that the OpenGL go-routine doesn't get switched
// to another thread (=> kerblammo)
runtime.LockOSThread()
if err := glfw.Init(); err != nil {
log.Panic("glfw Error:", err)
}
err := glfw.OpenWindow(w, h, 0, 0, 0, 0, 0, 0, glfw.Windowed)
if err != nil {
log.Panic("Error:", err)
}
if gl.Init() != 0 {
log.Panic("gl error")
}
if *vsync {
glfw.SetSwapInterval(1)
} else {
glfw.SetSwapInterval(0)
}
glfw.SetWindowTitle(title)
glfw.SetWindowSizeCallback(Reshape)
Init()
return func() {
glfw.Terminate()
glfw.CloseWindow()
log.Print("Cleanup")
}
}
示例10: RecoverPubkey
//recovers the public key from the signature
//recovery of pubkey means correct signature
func RecoverPubkey(msg []byte, sig []byte) []byte {
if len(sig) != 65 {
log.Panic()
}
var recid int = int(sig[64])
pubkey, ret := secp.RecoverPublicKey(
sig[0:64],
msg,
recid)
if ret != 1 {
log.Printf("RecoverPubkey: code %s", ret)
return nil
}
//var pubkey2 []byte = pubkey1.Bytes() //compressed
if pubkey == nil {
log.Panic("ERROR: impossible, pubkey nil and ret ==1")
}
if len(pubkey) != 33 {
log.Panic("pubkey length wrong")
}
return pubkey
//nonce1.SetBytes(nonce_seed)
}
示例11: ECDH
//raise a pubkey to the power of a seckey
func ECDH(pub []byte, sec []byte) []byte {
if len(sec) != 32 {
log.Panic()
}
if len(pub) != 33 {
log.Panic()
}
if VerifySeckey(sec) != 1 {
log.Printf("Invalid Seckey")
}
if ret := VerifyPubkey(pub); ret != 1 {
log.Printf("Invalid Pubkey, %d", ret)
return nil
}
pubkey_out := secp.Multiply(pub, sec)
if pubkey_out == nil {
return nil
}
if len(pubkey_out) != 33 {
log.Panic("ERROR: impossible, invalid pubkey length")
}
return pubkey_out
}
示例12: RemoveFromRegistry
func RemoveFromRegistry(r *RpcService) {
newServices := make([]*RpcService, 0)
for _, v := range NOS.Services {
if v != nil {
if !v.Equal(r) {
newServices = append(newServices, v)
}
}
}
NOS.Services = newServices
b, err := json.Marshal(NOS)
if err != nil {
log.Panic(err.String())
}
rev, err := DC.Rev()
if err != nil {
log.Panic(err.String())
}
_, err = DC.Set("/servers/config/networkservers.conf", rev, b)
if err != nil {
log.Panic(err.String())
}
}
示例13: RemoveService
func RemoveService(i int) {
newServices := make([]*RpcService, 0)
for k, v := range NOS.Services {
if k != i {
if v != nil {
newServices = append(newServices, v)
}
}
}
NOS.Services = newServices
b, err := json.Marshal(NOS)
if err != nil {
log.Panic(err.String())
}
rev, err := DC.Rev()
if err != nil {
log.Panic(err.String())
}
_, err = DC.Set("/servers/config/networkservers.conf", rev, b)
if err != nil {
log.Panic(err.String())
}
}
示例14: main
func main() {
robot := robot.NewRobot()
if err := robot.Start(); err != nil {
log.Panic(err)
}
bot, err := tgbotapi.NewBotAPI(os.Getenv("BOT_TOKEN"))
if err != nil {
log.Panic(err)
}
bot.Debug = true
u := tgbotapi.NewUpdate(0)
u.Timeout = 60
updates, err := bot.GetUpdatesChan(u)
if err != nil {
log.Panic(err)
}
for update := range updates {
log.Printf("[%s] %s", update.Message.From.UserName, update.Message.Text)
bot.Send(robot.Response(update.Message))
}
}
示例15: GetServerIP
func GetServerIP() string {
ifaces, err := net.Interfaces()
if err != nil {
log.Panic("Can't acess the network interfaces.")
}
var ip net.IP
for _, i := range ifaces {
addrs, err := i.Addrs()
if err != nil {
log.Panic("Can't read the IP.")
}
for _, addr := range addrs {
switch v := addr.(type) {
case *net.IPNet:
//log.Printf("Evaluating IPNet: %v\r\n", v.IP)
if (v.IP.To4() != nil) && !v.IP.IsLinkLocalUnicast() && !v.IP.IsLoopback() && !v.IP.IsMulticast() {
ip = v.IP
}
case *net.IPAddr:
//log.Printf("Evaluating IPAddr: %v\r\n", v.IP)
if (v.IP.To4() != nil) && !v.IP.IsLinkLocalUnicast() && !v.IP.IsLoopback() && !v.IP.IsMulticast() {
ip = v.IP
}
}
}
}
// process IP address
return ip.String()
}