the code is like this(i make it simple,but the logic is not change)
const (
Ignore = "-"
End = "\r\n"
)
type AccessLog struct {
Hash string
LowerIP string
FlowType int8
SendTime int64
Host string
AppName string
StreamName string
Protocol string
StatusCode string
Url string
HttpAgent string
Refer string
VideoFrameRate int32
.
.
.
omit some variable
.
.
.
}
func appendValue(rsp string, value string) string {
if value == End { // End
rsp += value
} else {
rsp += (value + "|")
}
return rsp
}
func (a *AccessLog) SetStatusCode(statusCode string) {
if a.StatusCode == "" {
a.StatusCode = statusCode
}
}
func (a *AccessLog) MakeString() string {
var rsp string
rsp = appendValue(rsp, Stop)
rsp = appendValue(rsp, a.Hash)
rsp = appendValue(rsp, a.LowerIP)
rsp = appendValue(rsp, fmt.Sprint(a.FlowType))
rsp = appendValue(rsp, fmt.Sprint(tt))
rsp = appendValue(rsp, a.Host)
rsp = appendValue(rsp, a.AppName)
rsp = appendValue(rsp, a.StreamName)
rsp = appendValue(rsp, a.Protocol)
rsp = appendValue(rsp, a.StatusCode) *//every time crash in this line,and
panic: **runtime error: invalid memory address or nil pointer dereference*
rsp = appendValue(rsp, a.Url)
rsp = appendValue(rsp, Ignore)
rsp = appendValue(rsp, Ignore)
.
.
.
}
*2 goroutinue will access the same variable which is type of *AccessLog ,like
this*
func changeAccessLog(a *AccessLog){
.
.
.
a.SetStatusCode(code)
.
.
.
}
func makeStringAccessLog(a *AccessLog) {
.
.
.
rsp := a.MakeString()
.
.
.
}
*//this is the caller function*
func callFunc(){
.
.
.
a := new(AccessLog)
go changeAccessLog(a)
go makeStringAccessLog(a)
.
.
.
}
so, i don't understand why operate string variable will case crash.
of course,the code in my program is more complex,function SetStatusCode and
MakeString will be called in the same time.
do somebody meet this before???????
--
You received this message because you are subscribed to the Google Groups
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.