毕业设计一周一记06

时间:2023-01-23 04:06:51

string

func TrimSpace

去除字符串的所有前导和尾随空格

 

net/url

 

type URL

type URL struct {       Scheme string

Opaque string // encoded opaque data

User *Userinfo // username and password information

 Host string // host or host:port  

Path string

RawQuery string // encoded query values, without '?'

Fragment string // fragment for references, without '#'

}

 

 

fmt.println的打印原理

// Println 使用其操作数的默认格式进行格式化并写入到标准输出。

// 其操作数之间总是添加空格,且总在最后追加一个换行符。

// 它返回写入的字节数以及任何遇到的错误。

 func Println(a ...interface{}) (n int, err error) { 

return Fprintln(os.Stdout, a...)

}

var (

    Stdin  = NewFile(uintptr(syscall.Stdin), "/dev/stdin")

    Stdout = NewFile(uintptr(syscall.Stdout), "/dev/stdout")

    Stderr = NewFile(uintptr(syscall.Stderr), "/dev/stderr")

)

type uintptr uintptr

uintptr 为整数类型,其大小足以容纳任何指针的位模式

syscall包中

var (

    Stdin  = 0

    Stdout = 1

    Stderr = 2

)

      // NewFile returns a new File with the given file descriptor and name.

           func NewFile(fd uintptr, name string) *File {

                  fdi := int(fd)

                  if fdi < 0 {

                         return nil

                  }

                  f := &File{&file{fd: fdi, name: name}}

                  runtime.SetFinalizer(f.file, (*file).close)

                  return f

           }

 

// Fprintln 使用其操作数的默认格式进行格式化并写入到 w

// 其操作数之间总是添加空格,且总在最后追加一个换行符。

// 它返回写入的字节数以及任何遇到的错误。

  func Fprintln(w io.Writer, a ...interface{}) (n int, err error) {

            p := newPrinter()

            p.doPrint(a, true, true)

            n, err = w.Write(p.buf)

            p.free()

            return

 }

 

// newPrinter 分配一个新的,或抓取一个已缓存的 pp 结构体。

      func newPrinter() *pp {

            p := ppFree.Get().(*pp)

            p.panicking = false

            p.erroring = false

            p.fmt.init(&p.buf)

            return p

       }

 

     type pp struct {

            n         int

            panicking bool

            erroring  bool // printing an error condition // 打印错误条件

            buf       buffer

            // arg holds the current item, as an interface{}.

            // arg 将当前条目作为 interface{} 类型的值保存。

            arg interface{}

            // value holds the current item, as a reflect.Value, and will be

            // the zero Value if the item has not been reflected.

            // value 将当前条目作为 reflect.Value 类型的值保存;若该条目未被反射,则为

            // Value 类型的零值。

            value reflect.Value

            // reordered records whether the format string used argument reordering.

             // reordered 记录该格式字符串是否用实参来重新排序。

            reordered bool

            // goodArgNum records whether the most recent reordering directive was valid.

            // goodArgNum 记录最近重新排序的指令是否有效。

            goodArgNum bool

            runeBuf    [utf8.UTFMax]byte

            fmt        fmt

     }

 

func (p *pp) doPrint(a []interface{}, addspace, addnewline bool) {

prevString := false

for argNum := 0; argNum < len(a); argNum++ {

p.fmt.clearflags()

// always add spaces if we're doing Println

// 若我们执行 Println 就总是添加空格

arg := a[argNum]

if argNum > 0 {

isString := arg != nil && reflect.TypeOf(arg).Kind() == reflect.String

if addspace || !isString && !prevString {

p.buf.WriteByte(' ')

}

}

prevString = p.printArg(arg, 'v', 0)

}

if addnewline {

p.buf.WriteByte('\n')

}

}

 

func (p *pp) doPrintf(format string, a []interface{}) {

    }// Println 使用其操作数的默认格式进行格式化并写入到标准输出。

// 其操作数之间总是添加空格,且总在最后追加一个换行符。

// 它返回写入的字节数以及任何遇到的错误。

 func Println(a ...interface{}) (n int, err error) { 

return Fprintln(os.Stdout, a...)

}

 

 

var (

    Stdin  = NewFile(uintptr(syscall.Stdin), "/dev/stdin")

    Stdout = NewFile(uintptr(syscall.Stdout), "/dev/stdout")

    Stderr = NewFile(uintptr(syscall.Stderr), "/dev/stderr")

)

type uintptr uintptr

uintptr 为整数类型,其大小足以容纳任何指针的位模式

syscall包中

var (

    Stdin  = 0

    Stdout = 1

    Stderr = 2

)

       // NewFile returns a new File with the given file descriptor and name.

           func NewFile(fd uintptr, name string) *File {

                  fdi := int(fd)

                  if fdi < 0 {

                         return nil

                  }

                  f := &File{&file{fd: fdi, name: name}}

                  runtime.SetFinalizer(f.file, (*file).close)

                  return f

           }

 

 

 

 

// Fprintln 使用其操作数的默认格式进行格式化并写入到 w

     // 其操作数之间总是添加空格,且总在最后追加一个换行符。

     // 它返回写入的字节数以及任何遇到的错误。

     func Fprintln(w io.Writer, a ...interface{}) (n int, err error) {

            p := newPrinter()

             p.doPrint(a, true, true)

             n, err = w.Write(p.buf)

             p.free()

             return

      }

 

// newPrinter 分配一个新的,或抓取一个已缓存的 pp 结构体。

      func newPrinter() *pp {

             p := ppFree.Get().(*pp)

             p.panicking = false

             p.erroring = false

             p.fmt.init(&p.buf)

             return p

      }

 

      type pp struct {

             n         int

             panicking bool

             erroring  bool // printing an error condition // 打印错误条件

             buf       buffer

             // arg holds the current item, as an interface{}.

             // arg 将当前条目作为 interface{} 类型的值保存。

       arg interface{}

       // value holds the current item, as a reflect.Value, and will be

       // the zero Value if the item has not been reflected.

       // value 将当前条目作为 reflect.Value 类型的值保存;若该条目未被反射,则为

            // Value 类型的零值。

            value reflect.Value

            // reordered records whether the format string used argument reordering.

              // reordered 记录该格式字符串是否用实参来重新排序。

              reordered bool

              // goodArgNum records whether the most recent reordering directive was valid.

              // goodArgNum 记录最近重新排序的指令是否有效。

              goodArgNum bool

              runeBuf    [utf8.UTFMax]byte

              fmt        fmt

       }

func (p *pp) doPrintf(format string, a []interface{}) {

             end := len(format)

             argNum := 0         // we process one argument per non-trivial format // 我们为每个非平凡格式都处理一个实参。

       afterIndex := false // previous item in format was an index like [3]. // 格式中的前一项是否为类似于 [3] 的下标。

             p.reordered = false

             for i := 0; i < end; {

                    p.goodArgNum = true

                    lasti := i

                    for i < end && format[i] != '%' {

                           i++

                    }

                    if i > lasti {

                           p.buf.WriteString(format[lasti:i])

                    }

                    if i >= end {

                           // done processing format string // 处理格式字符串完成

                           break

                    }

     

                    // Process one verb // 处理个占位符

                    i++

                    // Do we have flags? // 是否有标记?

                    p.fmt.clearflags()

             F:

                    for ; i < end; i++ {

                           switch format[i] {

                           case '#':

                                  p.fmt.sharp = true

                           case '0':

                                  p.fmt.zero = true

                           case '+':

                                  p.fmt.plus = true

                           case '-':

                                   p.fmt.minus = true

                            case ' ':

                                   p.fmt.space = true

                            default:

                                   break F

                            }

                     }

      

                     // Do we have an explicit argument index?

                     // 有显式的实参下标么?

                     argNum, i, afterIndex = p.argNumber(argNum, format, i, len(a))

      

                     // Do we have width?

                    // 有宽度不?

                    if i < end && format[i] == '*' {

                           i++

                           p.fmt.wid, p.fmt.widPresent, argNum = intFromArg(a, argNum)

                           if !p.fmt.widPresent {

                                  p.buf.Write(badWidthBytes)

                           }

                           afterIndex = false

                    } else {

                           p.fmt.wid, p.fmt.widPresent, i = parsenum(format, i, end)

                           if afterIndex && p.fmt.widPresent { // "%[3]2d"

                                  p.goodArgNum = false

                           }

                    }

                    // Do we have precision?

                    // 有精度不?

                    if i+1 < end && format[i] == '.' {

                           i++

                           if afterIndex { // "%[3].2d"

                                  p.goodArgNum = false

                           }

                           argNum, i, afterIndex = p.argNumber(argNum, format, i, len(a))

                            if i < end && format[i] == '*' {

                                   i++

                                   p.fmt.prec, p.fmt.precPresent, argNum = intFromArg(a, argNum)

                                   if !p.fmt.precPresent {

                                          p.buf.Write(badPrecBytes)

                                   }

                                  afterIndex = false

                           } else {

                                  p.fmt.prec, p.fmt.precPresent, i = parsenum(format, i, end)

                                  if !p.fmt.precPresent {

                                         p.fmt.prec = 0

                                         p.fmt.precPresent = true

                                  }

                           }

                    }

     

                    if !afterIndex {

                           argNum, i, afterIndex = p.argNumber(argNum, format, i, len(a))

                    }

     

                    if i >= end {

                           p.buf.Write(noVerbBytes)

                           continue

                    }

                    c, w := utf8.DecodeRuneInString(format[i:])

                    i += w

                    // percent is special - absorbs no operand

                    // 百分号是特殊的 —— 它不接受操作数

                    if c == '%' {

                           p.buf.WriteByte('%') // We ignore width and prec. // 我们忽略宽度和精度。

                           continue

                    }

                    if !p.goodArgNum {

                           p.buf.Write(percentBangBytes)

                           p.add(c)

                           p.buf.Write(badIndexBytes)

                           continue

                    } else if argNum >= len(a) { // out of operands // 超过操作数

                           p.buf.Write(percentBangBytes)

                           p.add(c)

                           p.buf.Write(missingBytes)

                           continue

                    }

                    arg := a[argNum]

                    argNum++

     

                    if c == 'v' {

                           if p.fmt.sharp {

                                  // Go syntax. Set the flag in the fmt and clear the sharp flag.

                                  p.fmt.sharp = false

                                  p.fmt.sharpV = true

                           }

                           if p.fmt.plus {

                                  // Struct-field syntax. Set the flag in the fmt and clear the plus flag.

                                   p.fmt.plus = false

                                   p.fmt.plusV = true

                            }

                     }

                     p.printArg(arg, c, 0)

       }

 

       // Check for extra arguments unless the call accessed the arguments

       // out of order, in which case it's too expensive to detect if they've all

       // been used and arguably OK if they're not.

       if !p.reordered && argNum < len(a) {

              p.buf.Write(extraBytes)

              for ; argNum < len(a); argNum++ {

                     arg := a[argNum]

                     if arg != nil {

                            p.buf.WriteString(reflect.TypeOf(arg).String())

                                  p.buf.WriteByte('=')

                           }

                           p.printArg(arg, 'v', 0)

                           if argNum+1 < len(a) {

                                  p.buf.Write(commaSpaceBytes)

                           }

                    }

                    p.buf.WriteByte(')')

             }

      }


用到的第三方代码库:   1.beego框架:一个go语言开发的web框架 安装: go get github.com/astaxie/beego 2.goquery:网页源代码获取过滤的第三方库 安装: go get github.com/PuerkitoBio/goquery 3.excelize框架:写入excel文件第三方库 安装: go get github.com/xuri/excelize   遇到问题: excel写入数据只能写入一部分: 猜想:线程相关超时直接跳过了,不执行写入文件操作