import "io/ioutil"

func main() { 
    content, err = iotuil.ReadFile("somefile.txt")
    // etc..
}

=》

I guess this doesn't really answer your question, but if you want, you can actually call the methods without explicitly stating the package - just import with a . in front of the names (but this is not recommended; see below):

package main

import (
  . "fmt"
  . "io/ioutil"
)

func main () {
  content, err := ReadFile("testfile")
  if err != nil {
    Println("Errors")
  }
  Println("My file:\n", string(content))
}

Note @jimt's comment below - this practice is not advised outside of tests as it could cause name conflicts with future releases. Also, definitely agree with @DavidGrayson's point of being nicer to read/see where things come from.

 

参考:https://stackoverflow.com/questions/12925450/importing-packages-in-go

相关文章:

  • 2022-03-04
  • 2022-12-23
  • 2021-10-12
  • 2021-06-13
  • 2022-02-18
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-03-08
  • 2021-09-23
  • 2022-01-17
  • 2021-07-23
  • 2021-08-08
相关资源
相似解决方案