Esempio n. 1
0
func ReadProperties(fname string) (map[string]string, error) {
	props := make(map[string]string)
	err := file.Filter(fname, func(_ int, line []byte) ([]byte, error) {
		p := pair.Parse(unsafe2.String(line), "=").Trim()
		if p.HasKey() {
			props[p.Key] = strings2.TrimAfter(p.Value, "#")
		}

		return line, nil
	})

	return props, err
}
Esempio n. 2
0
func (v Visitor) extractSQLs(docs []string) {
	const (
		INIT = iota
		PARSING

		GOMODEL = "//gomodel "
	)

	var (
		sqls  []string
		name  string
		state = INIT
	)

	for _, d := range docs {
		if state == PARSING {
			d = d[len("//"):]

			if strings.HasPrefix(d, "]") {
				v.SQLs[name] = strings.Join(sqls, " ")
				state = INIT
			} else {
				sqls = append(sqls, strings.TrimSpace(d))
			}

		} else if strings.HasPrefix(d, GOMODEL) {
			d = d[len(GOMODEL):]
			p := pair.Parse(d, "=").Trim()

			if !strings.HasSuffix(p.Value, "[") {
				v.SQLs[p.Key] = p.Value
			} else {
				name = p.Key
				sqls = sqls[:0]

				state = PARSING
			}
		}
	}
}