缩短Go / Golang中的进口变量出口?

if I have

// types.go

type S string

func (s *S) Lower() *S {
    *s = S(strings.ToLower(string(*s)))
    return s
}

`

// in another file

import "u/types"

func main() {
    s := types.S("asdf")
    if s == "asdf" {
        s.Lower()
    }
}
  1. Is there a way to shorten types.S("asdf") to just S("asdf")?

  2. Is there a way to lowercase method calls from other files? e.g. s.Lower() => s.lower()?

It's not recommended for most cases but you can do import . "u/types" and all then skip the types prefix. . will import all the public symbols into your package for you allowing you to call them as if they were local to your package.

  1. Not as long as that type is in a different package from where you're using it, without using dot-imports.

  2. Yes, if the other file is still in the same package. Otherwise, no, because then the function won't be exported (visible to other packages). This is Go convention.