2021年4月

golang 1.16 版提供了资源内嵌

import _ "embed"

//go:embed hello.txt
var s string
print(s)


import _ "embed"

//go:embed hello.txt
var b []byte
print(string(b))


import "embed"

//go:embed hello.txt
var f embed.FS
data, _ := f.ReadFile("hello.txt")
print(string(data))


package server

import "embed"

// content holds our static web server content.
//go:embed image/* template/*
//go:embed html/index.html
var content embed.FS

func main() {
    http.Handle("/static/", http.StripPrefix("/static/", http.FileServer(http.FS(content))))
    http.ListenAndServe(":8080", nil)
}

参考资料:
https://golang.org/pkg/embed/

package main

import (
    "fmt"

    "github.com/tealeg/xlsx"
)

func main() {
    xlFile, err := xlsx.OpenFile("Item.xlsx")
    if err != nil {
        panic(err.Error())
    }

    for _, v := range xlFile.Sheets[0].Rows {
        if len(v.Cells) > 0 {
            fmt.Printf("%s %s\n", v.Cells[1].String(), v.Cells[0].String())
        }
    }
}