本文整理汇总了Golang中log.Panicf函数的典型用法代码示例。如果您正苦于以下问题:Golang Panicf函数的具体用法?Golang Panicf怎么用?Golang Panicf使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Panicf函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: readEncDNA
func readEncDNA() []byte {
in, startTok := bufio.NewReader(os.Stdin), []byte(">THREE ")
for line, err := in.ReadSlice('\n'); !bytes.HasPrefix(line, startTok); line, err = in.ReadSlice('\n') {
if err != nil {
log.Panicf("Error: Could not read input from stdin; Details: %s", err)
}
}
ascii, err := ioutil.ReadAll(in)
if err != nil {
log.Panicf("Error: Could not read input from stdin; Details: %s", err)
}
j := 0
for i, c, asciic := 0, byte(0), len(ascii); i < asciic; i++ {
c = ascii[i]
switch c {
case 'a', 'A':
c = 0
case 't', 'T':
c = 1
case 'g', 'G':
c = 2
case 'c', 'C':
c = 3
case '\n':
continue
default:
log.Fatalf("Error: Invalid nucleotide value: '%c'", ascii[i])
}
ascii[j] = c
j++
}
return ascii[:j+1]
}
示例2: filterStateChanges
func filterStateChanges(in <-chan *dbus.Signal, out chan<- bool) {
for signal := range in {
if len(signal.Body) != 3 {
log.Panicf("protocol error: NetworkManager sent a StateChanged signal with %d members, expected 3\n", len(signal.Body))
}
newState, ok := signal.Body[0].(uint32)
if !ok {
log.Panicf("protocol error: NetworkManager sent a StateChanged signal where members are not uint32\n")
}
if newState != NM_DEVICE_STATE_ACTIVATED {
continue
}
// We don’t use NetworkManager’s CheckConnectivity method because it
// has many false-positives (at least with NetworkManager 1.0.6), i.e.
// it will say you have full connectivity, even though you are
// connected to an Android tethering hotspot without upstream
// connectivity. So, we save the code complexity of dealing with an API
// that doesn’t provide us useful data.
// Trigger a check if we can. If we can’t, the implication is that a
// check is currently running, which is fine as well.
select {
case out <- true:
default:
}
}
}
示例3: snapshot
// TODO: non-blocking snapshot
func (s *EtcdServer) snapshot(snapi uint64, confState *raftpb.ConfState) {
d, err := s.store.Save()
// TODO: current store will never fail to do a snapshot
// what should we do if the store might fail?
if err != nil {
log.Panicf("etcdserver: store save should never fail: %v", err)
}
err = s.raftStorage.Compact(snapi, confState, d)
if err != nil {
// the snapshot was done asynchronously with the progress of raft.
// raft might have already got a newer snapshot and called compact.
if err == raft.ErrCompacted {
return
}
log.Panicf("etcdserver: unexpected compaction error %v", err)
}
log.Printf("etcdserver: compacted log at index %d", snapi)
if err := s.storage.Cut(); err != nil {
log.Panicf("etcdserver: rotate wal file should never fail: %v", err)
}
snap, err := s.raftStorage.Snapshot()
if err != nil {
log.Panicf("etcdserver: snapshot error: %v", err)
}
if err := s.storage.SaveSnap(snap); err != nil {
log.Fatalf("etcdserver: save snapshot error: %v", err)
}
log.Printf("etcdserver: saved snapshot at index %d", snap.Metadata.Index)
}
示例4: route
func (r *Router) route(parts []string) *Router {
if len(parts) == 0 {
return r
}
part := parts[0]
if len(part) > 0 && part[0] == ':' {
part = part[1:]
if r.varName != "" && part != r.varName {
log.Panicf("overlapping vars: %q / %q", r.varName, part)
}
if r.varRouter == nil {
r.varName = part
r.varRouter = &Router{}
}
r = r.varRouter
} else if part == "*" {
if r.fallbackRouter != nil {
log.Panicf("overlapping fallback routes")
}
r.fallbackRouter = &Router{}
return r.fallbackRouter
} else {
if r.matchers == nil {
r.matchers = make(map[string]*Router)
}
if r.matchers[part] == nil {
r.matchers[part] = &Router{}
}
r = r.matchers[part]
}
return r.route(parts[1:])
}
示例5: InitFromString
func (m *Map) InitFromString(s string, hasBorder bool) {
m.SetNullDeadline()
lines := strings.Fields(s)
rows := len(lines)
var cols int
for row, line := range lines {
if row == 0 {
cols = len(line)
m.Init(rows, cols, 0, hasBorder)
} else {
if cols != len(line) {
log.Panicf("different-length lines in %v", lines)
}
}
for col, letter := range line {
p := Point{row, col}
switch letter {
case '.':
// Unknown territory
case '%':
m.MarkWater(p)
case '*':
m.MarkFood(p)
case 'a':
m.AddAnt(p, 0)
case 'b':
m.AddAnt(p, 1)
default:
log.Panicf("unknown letter: %v", letter)
}
}
}
SetAttackRadius2(5) // default for testing
}
示例6: Do_returns_json_array
func (c *RestClient) Do_returns_json_array(req *http.Request, opName string) (mresp []interface{}) {
start := time.Now()
resp, serialNumber := c.DoRaw(req, opName)
if resp == nil {
return
}
if !strings.HasPrefix(resp.Header.Get("Content-Type"), "application/json") {
log.Panicf("Non-JSON response for %v", req)
return
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
log.Panicf("Can't read HTTP response: %v", err)
return
}
if err = json.Unmarshal(body, &mresp); err != nil {
log.Panicf("Can't parse response JSON: %v\nrequest = %v\n%s", err, req, body)
}
if c.Verbose {
log.Printf("#%05d: finished in %v", serialNumber, time.Since(start))
}
return
}
示例7: membersFromStore
func membersFromStore(st store.Store) (map[types.ID]*Member, map[types.ID]bool) {
members := make(map[types.ID]*Member)
removed := make(map[types.ID]bool)
e, err := st.Get(storeMembersPrefix, true, true)
if err != nil {
if isKeyNotFound(err) {
return members, removed
}
log.Panicf("get storeMembers should never fail: %v", err)
}
for _, n := range e.Node.Nodes {
m, err := nodeToMember(n)
if err != nil {
log.Panicf("nodeToMember should never fail: %v", err)
}
members[m.ID] = m
}
e, err = st.Get(storeRemovedMembersPrefix, true, true)
if err != nil {
if isKeyNotFound(err) {
return members, removed
}
log.Panicf("get storeRemovedMembers should never fail: %v", err)
}
for _, n := range e.Node.Nodes {
removed[mustParseMemberIDFromKey(n.Key)] = true
}
return members, removed
}
示例8: addType
// AddType makes a type known to a schema
func (sch *Schema) addType(def ast.TypeDefinition) {
if !sch.mutable {
panic("Attempted to mutate schema after it has been finalized")
}
var name string
// Do extra type validation for Objects, Interfaces and Unions
switch t := def.(type) {
case *ast.ScalarDefinition:
name = t.Name
case *ast.EnumDefinition:
name = t.Name
case *ast.ObjectDefinition:
name = t.Name
assertFieldsUnique(t.Fields, t.Name)
case *ast.InterfaceDefinition:
name = t.Name
assertFieldsUnique(t.Fields, t.Name)
case *ast.UnionDefinition:
name = t.Name
if len(t.Members) == 0 {
log.Panicf("Union '%s' must have one or more member types", name)
}
}
if _, exists := sch.types[name]; exists {
log.Panicf("Type '%s' already exists in schema", name)
}
sch.types[name] = def
}
示例9: setupDrawer
func (t *Tiler) setupDrawer() {
t.bondFudgeX = int(Floor(float64(t.TileWidth) / 80))
t.bondFudgeY = int(Floor(float64(t.TileHeight) / 80))
t.fontSize = int(Sqrt(float64(t.TileHeight*t.TileWidth)) / 4)
t.tileHorizShift = int(float64(t.TileWidth) / 10)
t.tileVertShift = int(float64(t.TileHeight) / 10)
t.tileHorizMargin = int(float64(t.TileWidth) / 20)
t.tileVertMargin = int(float64(t.TileHeight) / 20)
bytes, err := ioutil.ReadFile(t.FontPath)
if err != nil {
log.Panicf("Couldn't read font: %s", err)
}
t.font, err = freetype.ParseFont(bytes)
if err != nil {
log.Panicf("Couldn't parse font: %s", err)
}
// figure out how big a representative character is for approximate layout purposes
ex := '5'
fupe := t.font.FUnitsPerEm()
horiz := t.font.HMetric(fupe, t.font.Index(ex))
vert := t.font.VMetric(fupe, t.font.Index(ex))
t.fontX = int(horiz.LeftSideBearing)
t.fontWidth = int(horiz.AdvanceWidth)
t.fontY = int(vert.TopSideBearing)
t.fontHeight = int(vert.AdvanceHeight)
log.Printf("%#v", t)
}
示例10: Update
func (m *Map) Update(words []string) {
if words[0] == "turn" {
turn := Turn(atoi(words[1]))
if turn != TURN+1 {
log.Panicf("Turn number out of sync, expected %v got %v", TURN+1, turn)
}
TURN = turn
log.SetPrefix(fmt.Sprintf("%s %d ", *logPrefix, turn))
return
}
p := Point{atoi(words[1]), atoi(words[2])}
var ant Item
if len(words) == 4 {
ant = Item(atoi(words[3]))
}
switch words[0] {
case "w":
m.MarkWater(p)
case "f":
m.MarkFood(p)
case "h":
m.MarkHill(p, ant)
case "a":
m.AddAnt(p, ant)
case "d":
m.DeadAnt(p, ant)
default:
log.Panicf("unknown command updating map: %v\n", words)
}
}
示例11: setupSocket
func setupSocket(pluginDir string, driverName string) string {
exists, err := dirExists(pluginDir)
if err != nil {
log.Panicf("Stat Plugin Directory error '%s'", err)
os.Exit(1)
}
if !exists {
err = createDir(pluginDir)
if err != nil {
log.Panicf("Create Plugin Directory error: '%s'", err)
os.Exit(1)
}
log.Printf("Created Plugin Directory: '%s'", pluginDir)
}
socketFile := pluginDir + "/" + driverName + ".sock"
exists, err = fileExists(socketFile)
if err != nil {
log.Panicf("Stat Socket File error: '%s'", err)
os.Exit(1)
}
if exists {
err = deleteFile(socketFile)
if err != nil {
log.Panicf("Delete Socket File error: '%s'", err)
os.Exit(1)
}
log.Printf("Deleted Old Socket File: '%s'", socketFile)
}
return socketFile
}
示例12: main
func main() {
log.SetFlags(log.Ldate | log.Ltime | log.Lshortfile)
// the server meeds a private key
// generate one with `ssh-keygen -t rsa`
pemBytes, err := ioutil.ReadFile("id_rsa")
if err != nil {
log.Panicf("Failed to load private key: %#v\n", err)
}
// pass the private key and an authentication function
server, err := sshgate.NewServer(pemBytes, Authenticate)
if err != nil {
log.Panicf("NewServer error: %#v\n", err)
}
// listen on specific port and address
// "" is equivalent to "0.0.0.0" or “all interfaces”
port, err := strconv.Atoi(os.Getenv("PORT"))
if err != nil {
log.Panicf("Can't parse port: %#v\n", err)
}
if err := server.Listen("", port); err != nil {
log.Panicf("Listen error: %#v\n", err)
}
}
示例13: inboundConnectionCandidates
func inboundConnectionCandidates(neuron *ng.Neuron) []*ng.NodeId {
if neuron == nil {
log.Panicf("neuron is nil")
}
cortex := neuron.Cortex
if cortex == nil {
log.Panicf("neuron has no cortex associated: %v", neuron)
}
neuronNodeIds := cortex.NeuronNodeIds()
sensorNodeIds := cortex.SensorNodeIds()
availableNodeIds := append(neuronNodeIds, sensorNodeIds...)
// hackish way to delete a vew elements from this slice.
// put in a map and delete from map, then back to slice. TODO: fixme
availableNodeIdMap := make(map[string]*ng.NodeId)
for _, nodeId := range availableNodeIds {
availableNodeIdMap[nodeId.UUID] = nodeId
}
// remove things we already have inbound connections from
for _, inboundConnection := range neuron.Inbound {
nodeId := inboundConnection.NodeId
delete(availableNodeIdMap, nodeId.UUID)
}
availableNodeIds = make([]*ng.NodeId, 0)
for _, nodeId := range availableNodeIdMap {
availableNodeIds = append(availableNodeIds, nodeId)
}
return availableNodeIds
}
示例14: handleFreezeRequest
func (server *Server) handleFreezeRequest(freq *freezeRequest, fs *frozenServer) {
pr, pw := io.Pipe()
freq.readCloser = pr
freq.done <- true
zw, err := gzip.NewWriterLevel(pw, gzip.BestCompression)
if err != nil {
if err = pw.CloseWithError(err); err != nil {
log.Panicf("Unable to close PipeWriter: %v", err.String())
}
return
}
enc := gob.NewEncoder(zw)
err = enc.Encode(fs)
if err != nil {
if err = pw.CloseWithError(err); err != nil {
log.Panicf("Unable to close PipeWriter: %v", err.String())
}
}
if err = pw.CloseWithError(zw.Close()); err != nil {
log.Panicf("Unable to close PipeWriter: %v", err.String())
}
}
示例15: Send
func (s *SimplePoint) Send(r *Request) {
if s.b.ch == nil {
panic("EndPoint is not running")
}
if !s.standalone {
log.Panicf("you should not call Send on child endpoint %+v", s)
}
if !r.SetPending() {
/* this could happen if SetDeadline already respond with timeout */
if r.Performed() {
return
}
log.Panicf("Request already sent somewhere %+v")
}
r.SetTimeout(s.Timeout)
/* this could happen if SetDeadline already respond with timeout */
if r.Performed() {
return
}
s.b.push(r)
}