當前位置: 首頁>>代碼示例>>Golang>>正文


Golang err.Panic函數代碼示例

本文整理匯總了Golang中github.com/Cergoo/gol/err.Panic函數的典型用法代碼示例。如果您正苦於以下問題:Golang Panic函數的具體用法?Golang Panic怎麽用?Golang Panic使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了Panic函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: chekloop

// 2. Контроль зацикливаний тега tTagIncludeCon
func chekloop(tpls map[string]parser.Ttpl) {
	var (
		key   string
		mitem = []interface{}{}
	)
	matrix := make(map[interface{}][]interface{}, len(tpls))
	for key = range tpls {
		for _, item := range tpls[key] {
			switch v := item.(type) {
			case tTagIncludeVar:
				if key == v[0] {
					err.Panic(err.New("Error: loops detection: "+key+" - "+key, 0))
				}
				mitem = append(mitem, v[0])
			}
		}
		if len(mitem) > 0 {
			matrix[key] = mitem
		}
	}
	loop := tarjan.Connections(matrix)
	for i := range loop {
		if len(loop[i]) > 1 {
			err.Panic(err.New("Error: loops detection: "+fmt.Sprint(loop[i]), 0))
		}
	}
}
開發者ID:catgatp,項目名稱:gol,代碼行數:28,代碼來源:tplengin.go

示例2: parseTagPlural

// parse plural tag
func parseTagPlural(source []string) *tTagPlural {
	if len(source) < 2 {
		err.Panic(err.New("error parsing to Plural Tag: "+fmt.Sprint(source), 0))
	}
	i, e := strconv.ParseUint(source[1], 10, 16)
	err.Panic(e)
	return &tTagPlural{uint16(i), []string{source[0]}}
}
開發者ID:catgatp,項目名稱:gol,代碼行數:9,代碼來源:i18n.go

示例3: decode

func (t *TGen) decode(val reflect.Type) {
	v, ok := t.stackName.Pop()
	if !ok {
		err.Panic(err.New("stack name empty", 0))
	}
	name := v.(string)

	switch val.Kind() {
	case reflect.Uint8:
		t.decUint8(name)
	case reflect.Uint16:
		t.decUint16(name)
	case reflect.Uint32:
		t.decUint32(name)
	case reflect.Uint64:
		t.decUint64(name)
	case reflect.Uint:
		t.decUint(name)
	case reflect.Int8:
		t.decInt8(name)
	case reflect.Int16:
		t.decInt16(name)
	case reflect.Int32:
		t.decInt32(name)
	case reflect.Int64:
		t.decInt64(name)
	case reflect.Int:
		t.decInt(name)
	case reflect.Float32:
		t.decFloat32(name)
	case reflect.Float64:
		t.decFloat64(name)
	case reflect.Complex64:
		t.decComplex64(name)
	case reflect.Complex128:
		t.decComplex128(name)
	case reflect.Bool:
		t.decBool(name)
	case reflect.String:
		t.decString(name)
	case reflect.Slice:
		t.decSlice(name, val)
	case reflect.Array:
		t.decArray(name, val)
	case reflect.Ptr:
		t.decPtr(name, val)
	case reflect.Struct:
		t.decStruct(name, val)
	case reflect.Map:
		t.decMap(name, val)
	case reflect.Interface:
		err.Panic(err.New("interface type not supported, only strong typed", 0))
	}
}
開發者ID:catgatp,項目名稱:gol,代碼行數:54,代碼來源:decoder.go

示例4: Add

// Add add to function map
func (t FuncMap) Add(name string, f interface{}) {
	v := reflect.ValueOf(f)
	if v.Kind() != reflect.Func {
		err.Panic(err.New(errNotFunction, 0))
	}
	t[name] = v
}
開發者ID:catgatp,項目名稱:gol,代碼行數:8,代碼來源:caller.go

示例5: parseTag

func parseTag(source []byte) (tag interface{}) {
	defer func() {
		if e := recover(); e != nil {
			v := e.(*err.OpenErr)
			v.Text += "err parse tpl: " + string(source)
			err.Panic(v)
		}
	}()

	list := parser.SplitWord(source, 32)
	switch list[0] {
	// основные теги
	case "!":
	case "inc":
		tag = parseTagInclude(list[1:])
	case "i18n":
		tag = parseTagi18n(list[1:])
	case "for":
		tag = parseTagFor(list[1:])
	default:
		// переменная контекста
		// либо функция (расширенные теги)
		slice := []byte(list[0])
		if bytes.HasPrefix(slice, []byte(".")) {
			tag = tTagVar(list[0][1:])
		} else if bytes.HasPrefix(slice, []byte("@.")) {
			tag = tTagVarHtmlEsc(list[0][2:])
		} else {
			tag = parseTagFunc(list)
		}
	}
	return
}
開發者ID:catgatp,項目名稱:gol,代碼行數:33,代碼來源:tplengin.go

示例6: Replace

func (t *TReplaser) Replace(name string, v map[string]interface{}, writer io.Writer) {
	tpl := t.tpl.tpl[name]
	if tpl == nil {
		err.Panic(err.New("Err, tpl '"+name+"' not found", 0))
	}
	t.replace(tpl, v, writer)
}
開發者ID:catgatp,項目名稱:gol,代碼行數:7,代碼來源:tplengin.go

示例7: Call

// Call call function from a function map
func (t FuncMap) Call(name string, params ...interface{}) []reflect.Value {
	f, e := t[name]
	if !e {
		err.Panic(err.New(errFunctionNotFound, 0))
	}
	return call(f, params...)
}
開發者ID:catgatp,項目名稱:gol,代碼行數:8,代碼來源:caller.go

示例8: parseTagVar

// parse context var tag
func parseTagVar(source []string) (v *tTagVar) {
	i, e := strconv.ParseUint(source[0], 10, 16)
	err.Panic(e)
	v = &tTagVar{id: uint16(i)}
	if len(source) > 1 {
		v.format = source[1]
	}
	return
}
開發者ID:catgatp,項目名稱:gol,代碼行數:10,代碼來源:i18n.go

示例9: call

func call(f reflect.Value, params ...interface{}) []reflect.Value {
	if len(params) != f.Type().NumIn() {
		err.Panic(err.New(errNumberParamsNotAdapted, 0))
	}
	in := make([]reflect.Value, len(params))
	for k, param := range params {
		in[k] = reflect.ValueOf(param)
	}
	return f.Call(in)
}
開發者ID:catgatp,項目名稱:gol,代碼行數:10,代碼來源:caller.go

示例10: Encode

// Encode generate encode function from value
func (t *TGen) Encode(val interface{}) {
	valType := reflect.TypeOf(val)
	t.src = "\nfunc Encode(buf IBuf, t " + TypeName(valType.String(), true) + ") {\n"
	t.stackName.Push("t")
	t.encode(valType)
	t.src += "}\n\n"
	t.stackName.Clear()
	t.tmpNameGen.Clear()
	_, e := t.f.Write([]byte(t.src))
	err.Panic(e)
}
開發者ID:catgatp,項目名稱:gol,代碼行數:12,代碼來源:encoder.go

示例11: Decode

// Decode generate decode function from value
func (t *TGen) Decode(val interface{}) {
	valType := reflect.TypeOf(val)
	t.src = "\nfunc Decode(buf IBuf) (t " + TypeName(valType.String(), true) + ", e error) {\n"
	t.src += "var (\npart []byte\nbt byte\nln uint32\n)\n\n"
	t.stackName.Push("t")
	t.decode(valType)
	t.src += "return\n}\n\n"
	t.stackName.Clear()
	t.tmpNameGen.Clear()
	_, e := t.f.Write([]byte(t.src))
	err.Panic(e)
}
開發者ID:catgatp,項目名稱:gol,代碼行數:13,代碼來源:decoder.go

示例12: parseTagFunc

// parse user functions tag
func parseTagFunc(source []string) (v *tTagFunction) {
	var (
		i uint64
		e error
	)
	v = &tTagFunction{fname: source[0]}
	for _, val := range source[1:] {
		i, e = strconv.ParseUint(val, 10, 16)
		err.Panic(e)
		v.vars = append(v.vars, uint16(i))
	}
	return
}
開發者ID:catgatp,項目名稱:gol,代碼行數:14,代碼來源:i18n.go

示例13: parseTagFor

// parseTagi18n
func parseTagFor(source []string) interface{} {
	var m [2]string
	if len(source) < 3 {
		err.Panic(err.New("error parse tag 'For'", 0))
	}
	if source[0][0] == 46 {
		if len(source[0]) > 1 {
			m[0] = source[0][1:]
		} else {
			m[0] = "."
		}
		return tTagi18nVar(m)
	}
	m[0] = source[0]
	return &tTagFor{}
}
開發者ID:catgatp,項目名稱:gol,代碼行數:17,代碼來源:tplengin.go

示例14: tagIncludeCon_Init

// 3. for a tTagIncludeCon init before use
func (t *Ttpl) tagIncludeCon_Init() {
	for key, val := range t.tpl {
		for key1 := range val {
			switch v := val[key1].(type) {
			case tTagIncludeVar:
				// не полное имя и не имя переменной контекста - значит короткое имя
				if v[0][0] == 47 {
					tpl := t.tpl[v[0]]
					if tpl == nil {
						err.Panic(err.New("Err parse from tpl: '"+key+"' include tag. Not found tpl: '"+v[0]+"'", 0))
					}
					val[key1] = &tTagIncludeCon{tpl: tpl, contextVar: v[1]}
				}
			}
		}
	}
}
開發者ID:catgatp,項目名稱:gol,代碼行數:18,代碼來源:tplengin.go

示例15: Load

// Loade template
func (t *Ttpl) Load(patch string) {
	var (
		fileSource []byte
	)
	base := "/" + filepath.Base(patch) + "/"

	toparse := new(parser.ToParse)
	toparse.Delimiter[0] = []byte("{{")
	toparse.Delimiter[1] = []byte("}}")
	toparse.ParseTag = parseTag
	toparse.ParseText = parseText

	fileList, e := ioutil.ReadDir(patch)
	err.Panic(e)
	for _, item := range fileList {
		fileSource, e = ioutil.ReadFile(patch + "/" + item.Name())
		t.tpl[base+item.Name()] = parser.Parse(fileSource, toparse)
	}
}
開發者ID:catgatp,項目名稱:gol,代碼行數:20,代碼來源:tplengin.go


注:本文中的github.com/Cergoo/gol/err.Panic函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。