本文整理汇总了Golang中encoding/csv.Read函数的典型用法代码### 示例。如果您正苦于以下问题:Golang Read函数的具体用法?Golang Read怎么用?Golang Read使用的例子?那么恭喜您, 这里精选的函数代码### 示例或许可以为您提供帮助。

在下文中一共展示了Read函数的9个代码### 示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码### 示例。

示例1: compareToFixtures

func compareToFixtures(region holidays.Region, file string) error {
    fd, err := os.Open(file)
    if err != nil {
        return fmt.Errorf("Couldn't open fixtures '%s': %s", file, err)
    }
    csv := csv.NewReader(fd)

    for {
        day, err := csv.Read()
        if err == io.EOF {
            break
        }
        dt, err := time.Parse("2006-01-02", day[0])
        if err != nil {
            return fmt.Errorf("Couldn't parse fixtures: %s", err)
        }
        t := dt.Add(5 * time.Hour)
        holiday, err := holidays.Holiday(t, region)
        if err != nil {
            return fmt.Errorf("%s is supposed to be a holiday but library disagrees", t)
        }

        if holiday.Name != day[1] {
            return fmt.Errorf("Holiday/library: %s, fixture: %s", holiday.Name, day[1])
        }
    }
    return nil
}

开发者ID:soundcloud,项目名称:pager-hours,代码行数:28,代码来源:holidays_test.go

示例2: NewRoute

// Prepares the route to be used in matching.
func NewRoute(method, path, action, fixedArgs, routesPath string, line int) (r *Route) {
    // Handle fixed arguments
    argsReader := strings.NewReader(fixedArgs)
    csv := csv.NewReader(argsReader)
    fargs, err := csv.Read()
    if err != nil && err != io.EOF {
        ERROR.Printf("Invalid fixed parameters (%v): for string '%v'", err.Error(), fixedArgs)
    }

    r = &Route{
        Method:      strings.ToUpper(method),
        Path:        path,
        Action:      action,
        FixedParams: fargs,
        TreePath:    treePath(strings.ToUpper(method), path),
        routesPath:  routesPath,
        line:        line,
    }

    // URL pattern
    if !strings.HasPrefix(r.Path, "/") {
        ERROR.Print("Absolute URL required.")
        return
    }

    actionSplit := strings.Split(action, ".")
    if len(actionSplit) == 2 {
        r.ControllerName = actionSplit[0]
        r.MethodName = actionSplit[1]
    }

    return
}

开发者ID:elvislei,项目名称:revel,代码行数:34,代码来源:router.go

示例3: produce

func produce(channel chan Prescription, filename string) {
    //open file
    fi, err := os.Open(filename)
    if err != nil {
        panic(err)
    }

    csv := csv.NewReader(fi)

    skip := true

    fmt.Println("producing")

    for {
        record, err := csv.Read()
        if err != nil {
            break
        } else if err == io.EOF {
            break
        }

        if skip != false {
            skip = false
            continue
        }
        pres := NewPrescription(record)
        channel <- pres
    }
    close(channel)

}

开发者ID:nleite,项目名称:mongoexamples,代码行数:31,代码来源:sample.go

示例4: csv2db

func csv2db(filepath string, max_rows int) DB {
    // Read CSV file
    csvFile, err := os.Open(filepath)
    if err != nil {
        panic(err)
    }
    defer csvFile.Close()

    // For each line convert to struct
    csv := csv.NewReader(csvFile)
    columns, err := csv.Read()
    if err != nil {
        panic(err)
    }
    rows := []Row{}
    for {
        line, err := csv.Read()
        if err == io.EOF || (max_rows == len(rows) && max_rows != -1) {
            break
        }
        rows = append(rows, line)
    }
    return DB{columns, rows}
}

开发者ID:pratyushmittal,项目名称:goql,代码行数:24,代码来源:main.go

示例5: NewBinder

func NewBinder(reader io.Reader, opts *Options) (*Binder, error) {

    csv := csv.NewReader(reader)
    csv.FieldsPerRecord = -1

    if opts == nil {
        opts = &Options{}
    } else {
        if opts.Separator == 0 {
            opts.Separator = ','
        }
        csv.Comma = opts.Separator
    }

    if opts.TimeZone == nil {
        opts.TimeZone = time.UTC
    }

    var meta map[int]string

    if len(opts.Header) == 0 {
        header, err := csv.Read()

        if err != nil {
            return nil, err
        }

        meta = make(map[int]string)
        for i, col := range header {
            if opts.StripBOM && i == 0 {
                // Remove BOM
                col = strings.Replace(col, "\ufeff", "", -1)
            }
            meta[i] = col
        }
        if len(meta) == 0 {
            return nil, ErrNoHeader
        }
    } else {
        meta = opts.Header
        if len(meta) == 0 {
            return nil, ErrNoCustomHeader
        }
    }

    return &Binder{csv: csv, meta: meta, opts: opts}, nil
}

开发者ID:relops,项目名称:csvb,代码行数:47,代码来源:csvb.go

最后编辑: kuteng  文档更新时间: 2021-08-23 19:14   作者:kuteng