package main
import (
"awesomeProject/logger"
"fmt"
"github.com/opencontainers/runtime-tools/filepath"
"os"
)
type Goods struct {
ID uint
MonTs string
}
func Mkfile() {
filepaht := filepath.Join(os.TempDir(), "nginx")
if _, err := os.Stat(filepaht); os.IsNotExist(err) {
err = os.MkdirAll(filepaht, 0644)
if err != nil {
logger.DefaultLogger.Errorf("%v", err)
}
}
}
func GetId(id uint) *Goods {
return &Goods{ID: id}
}
func (g *Goods) GetMontsAdd(m string) *Goods {
g.MonTs = m
return g
}
func main() {
g := GetId(100).GetMontsAdd("TE")
fmt.Println(g) //{100 TE}
}
package main
import (
"awesomeProject/logger"
"fmt"
"github.com/opencontainers/runtime-tools/filepath"
"os"
)
type Goods struct {
ID uint
MonTs string
}
func Mkfile() {
filepaht := filepath.Join(os.TempDir(), "nginx")
if _, err := os.Stat(filepaht); os.IsNotExist(err) {
err = os.MkdirAll(filepaht, 0644)
if err != nil {
logger.DefaultLogger.Errorf("%v", err)
}
}
}
func (g *Goods) GetId(id uint) *Goods {
g.ID = id
return g
}
func (g *Goods) GetMonts(m string) *Goods {
g.MonTs = m
fmt.Printf("%T\n", g)
return g
}
func main() {
var g Goods
g.GetId(100).GetMonts("test")
fmt.Println(g) //{100 test}
}
package main
import (
"awesomeProject/logger"
"fmt"
"github.com/opencontainers/runtime-tools/filepath"
"os"
)
type Goods struct {
ID uint
MonTs string
}
func Mkfile() {
filepaht := filepath.Join(os.TempDir(), "nginx")
if _, err := os.Stat(filepaht); os.IsNotExist(err) {
err = os.MkdirAll(filepaht, 0644)
if err != nil {
logger.DefaultLogger.Errorf("%v", err)
}
}
}
func (g *Goods) GetId(id uint) uint {
g.ID = id
return g.ID
}
func (g *Goods) GetMonts(m string) string {
g.MonTs = m
return g.MonTs
}
func main() {
var g *Goods (改为var g Goods)
g.GetId(100)标签:Goods,err,增法,filepaht,逃逸,MonTs,func,go,os From: https://www.cnblogs.com/cheyunhua/p/16949422.html
g.GetMonts("test")
fmt.Println(g)
} 报错 runtime error: invalid memory address or nil pointer dereference