zoukankan      html  css  js  c++  java
  • golang import all 类似python import * 效果

    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:
    ", 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

  • 相关阅读:
    SpringBoot优雅的全局异常处理
    react格式化展示json
    Pycharm调试按钮
    HttpURLConnection和okhttp的使用
    objection自动生成hook代码
    hookString
    python取中位数 位运算
    scrapy mongo pipeline
    xpath tips
    IT日语
  • 原文地址:https://www.cnblogs.com/bonelee/p/6899687.html
Copyright © 2011-2022 走看看