自定义节拍运行错误:无效的持续时间 “ns”。

huangapple go评论86阅读模式
英文:

custum beat running error : invalid duration "ns"

问题

我正在工作的是一个自定义节拍器,它解码二进制文件以提取数据并将其发送到elasticsearch,编译过程正常,但当我运行它时,它给出一个运行时错误,错误是一个无效的持续时间"ns",以下是我的代码:

package beater

import (
	"fmt"
	"io/ioutil"
	"math"
	"time"
	"strconv"
	"strings"

	"github.com/elastic/beats/libbeat/beat"
	"github.com/elastic/beats/libbeat/common"
	"github.com/elastic/beats/libbeat/logp"
	"github.com/elastic/beats/libbeat/publisher"

	"github.com/bob96/hc34/config"
)

type Hc34 struct {
	done   chan struct{}

	config config.Config

	client publisher.Client

	siteKey string

	fileKey string

	callEndDateTime string

	callStartDateTime string

	callerPartyNumber string

	calledPartyNumber string

	incomingTrunkKey string

	outgoingTrunkKey string

	blockNumber string

	blockDateTime string

	headerFunction int

	headerUser int

	callerCategory int

	callerOrigineIdentity string

	complementaryIdentity string

	calledDigits string

	traficType int

	serviceType int

	supportService int

	chargeDuration int

	chargeMeters int

	outgoingTrunk string

	reserved string

	operatorIdentity string

	operatorServiceType string

	block string

	filekey string

	lastIndexTime time.Time
}

// 创建beater
func New(b *beat.Beat, cfg *common.Config) (beat.Beater, error) {
	config := config.DefaultConfig
	if err := cfg.Unpack(&config); err != nil {
		return nil, fmt.Errorf("Error reading config file: %v", err)
	}

	bt := &Hc34{
		done: make(chan struct{}),
		config: config,
	}
	return bt, nil
}

func (bt *Hc34) Run(b *beat.Beat) error {
	logp.Info("hc34 is running! Hit CTRL-C to stop it.")

	bt.client = b.Publisher.Connect()
	ticker := time.NewTicker(bt.config.Period)
	//counter := 1
	for {
		now := time.Now()
		bt.hc34DataHolderfunc(bt.config.Path)
		bt.lastIndexTime = now
		logp.Info("Event sent")
		select {
		case <-bt.done:
			return nil
		case <-ticker.C:
		}

		/*event := common.MapStr{
			"@timestamp": common.Time(time.Now()),
			"type":       b.Name,
			"counter":    counter,
		}
		bt.client.PublishEvent(event)
		logp.Info("Event sent")
		counter++*/
	}
}

func (bt *Hc34) Stop() {
	bt.client.Close()
	close(bt.done)
}

// 检查错误
func check(e error) {
	if e != nil {
		panic(e)
	}
}

func (bt *Hc34) hc34DataHolderfunc(dirfile string) {
	// 读取二进制文件
	data, err := ioutil.ReadFile(dirfile)
	check(err)
	//t := f.ModTime()
	bt.hc34decoderfunc(string(data))

	event := common.MapStr{
		"@timestamp": common.Time(time.Now()),
		/*"siteKey": siteKey,
		"fileKey": fileKey,*/
		//"callEndDateTime":	bt.callEndDateTime,
		//"callStartDateTime": bt.callStartDateTime,
		"callerPartyNumber": bt.callerPartyNumber,
		"calledPartyNumber": bt.calledPartyNumber,
		//"incomingTrunkKey": bt.incomingTrunkKey,
		//"outgoingTrunkKey": bt.outgoingTrunkKey,
		"blockNumber": bt.blockNumber,
		"blockDateTime": bt.blockDateTime,
		"headerFunction": bt.headerFunction,
		"headerUser": bt.headerUser,
		"callerCategory": bt.callerCategory,
		"callerOrigineIdentity": bt.callerOrigineIdentity,
		"complementaryIdentity": bt.complementaryIdentity,
		"calledDigits": bt.calledDigits,
		"traficType": bt.traficType,
		"serviceType": bt.serviceType,
		"supportService": bt.supportService,
		"chargeDuration": bt.chargeDuration,
		"chargeMeters": bt.chargeMeters,
		//"outgoingTrunk": bt.outgoingTrunk,
		"reserved": bt.reserved,
		"peratorIdentity": bt.operatorIdentity,
		"operatorServiceType": bt.operatorServiceType,
	}
	bt.client.PublishEvent(event)


}

type hc34decoder struct{
	block string
	siteKey string
	filekey string
}

func (bt *Hc34) hc34decoderfunc(block string){
	// 从块中获取头部(32字节)和内容(1932字节)
	
	header :=block[0:64]
	content :=block[64:len(block)]
	// 从头部获取块键和日期时间
	blockKey :=header[4:10]
	yearBlock :=header[10:12]
	//BDTdecode, err := hex.DecodeString(header[10:12])

	bt.blockDateTime =bt.getDate(bt.getDateBlockHeader(header[10:22]))
	/*if err != nil {
		log.Fatal(err)
	}*/
	// 处理内容以提取CDR
	start := 0
	totalCdr := len(content) / 84
	for z := 0; z < totalCdr; z++ {
		record := content[start:start + 84]
		start = start + 84
		// 从单个记录中提取数据
		//CEDdecode, err :=hex.DecodeString(record[10:12])
		a:= hex2decimal(record[54:56])
		headerFunction:= hex2decimal(record[0:2])
		headerUser:= hex2decimal(record[2:4])
		callerCategory:= hex2decimal(record[4:6])
		callEndDateTime :=bt.getDate(bt.getDateCall(record[6:16], yearBlock))
		callerOrigineIdentity:= strings.Replace(string(record[16:26]),"F","", -1)
		complementaryIdentity := strings.Replace(string(record[26:36]),"F","", -1)
		calledDigits:= strings.Replace(string(record[36:54]),"F","", -1)
		traficType:= hex2decimal(strings.Replace(string(a),"F","", -1))
		serviceType := hex2decimal(record[56:58])
		supportService :=hex2decimal(record[58:60])
		duration :=hex2decimal(record[60:64])
		meters:= hex2decimal(record[64:70])
		//outgoingTrunk :=strings.Replace(string(record[70:74]),"F", "",-1)
		bt.reserved = record[74:78]
		bt.operatorIdentity = strings.Replace(string(record[78:82]),"F", "",-1)
		bt.operatorServiceType =record[82:84]
		bt.blockNumber=blockKey
		bt.callerPartyNumber = bt.getFormattedMsisdnHc34Caller(complementaryIdentity, callerOrigineIdentity)
		bt.calledPartyNumber = bt.getFormattedMsisdnHc34Called(calledDigits)

		bt.callStartDateTime  = bt.getStartDate(callEndDateTime, int(duration) )
		/*if err !=nil{
			log.Fatal(err)
		}*/
		bt.headerFunction=int(headerFunction)
		bt.headerUser=int(headerUser)
		bt.callerCategory=int(callerCategory)
		bt.traficType=int(traficType)
		bt.serviceType=int(serviceType)
		bt.supportService=int(supportService)
		bt.chargeMeters=int(meters)
		bt.chargeDuration=int(duration)
	}
}

func (bt *Hc34) getStartDate(endTime string, duration int) string{
	layout := "2006-01-02T15:04:05.000Z"
	t, err := time.Parse(layout, endTime)
	if err!=nil{
		panic(err)
	}
	return (t.Add(time.Duration(-duration) * time.Second)).String()

}

/**
 * 获取通话的日期。
 * @param input 量化日期
 * @param year 年份
 * @return 通话日期
 */
func (bt *Hc34) getDateCall(input string,year string) string{
	quant:= hex2decimal(input[1:4])
	hour := input[4:len(input)]

	return "20" + year + bt.getQuantDate(quant) + "" + hour
}

/**
 * 获取块头的日期。
 * @param input 量化日期
 * @return 块头日期
 */
func(bt *Hc34) getDateBlockHeader(input string) string{
	year := input[0:2]
	quant:= hex2decimal(input[3:6])
	hour := input[6:len(input)];
	/*if err!=nil{
		panic(err)
	}*/
	return "20" + year + bt.getQuantDate(quant) + "" + hour
}

/**
 * 格式化日期。
 * @param date 日期
 * @return 格式化后的日期
 */

func(bt *Hc34) getDate(date string) string{
	year := date[0:4]
	month := date[4:6]
	day := date[6:8]
	hour := date[8:10]
	minute := date[10:12]
	second := date[12:14]
	return year + "-" + month + "-" + day + " " + hour + ":" + minute + ":" + second;
}
/**
 * 格式化量化日期。
 * @param quant 量化日期
 * @return 格式化后的日期
 */
func(bt *Hc34) getQuantDate(quant int) string{
	nanoDayOfYear:=string(quant*24*60*60*1000*1000*1000) + "ns"
	durt,err:=time.ParseDuration(nanoDayOfYear)
	t := time.Date(2009, time.January, 01, 00, 0, 0, 0, time.UTC)
	t=t.Add(durt)
	if err!=nil{

		panic(err)
	}
	return string(t.Month())+""+string(t.Day())

}
func bin(i int, prefix bool) string {
	i64 := int64(i)

	if prefix {
		return "0b" + strconv.FormatInt(i64, 2) // base 2 for binary
	} else {
		return strconv.FormatInt(i64, 2) // base 2 for binary
	}
}

func bin2int(binStr string) int {

	// base 2 for binary
	result, _ := strconv.ParseInt(binStr, 2, 64)
	return int(result)
}


func hex(i int, prefix bool) string {
	i64 := int64(i)

	if prefix {
		return "0x" + strconv.FormatInt(i64, 16) // base 16 for hexadecimal
	} else {
		return strconv.FormatInt(i64, 16) // base 16 for hexadecimal
	}
}

func hex2int(hexStr string) int {
	// base 16 for hexadecimal
	result, _ := strconv.ParseInt(hexStr, 16, 64)
	return int(result)
}
func hex2decimal(hexStr string) int{

	base16 := 16;

	var val float64
	for i:=0; i>len(hexStr);i++{
		vala:=hex2int(string(base16))
		valo:=hex2int(string(hexStr[len(hexStr)-i]))
		val+=float64(valo)*math.Pow(float64(vala),float64(i))
	}
	return int(val)

}

这是我遇到的错误:

panic: time: invalid duration ns
goroutine 1 [running]:
github.com/bob96/hc34/beater.(*Hc34).getQuantDate(0xc42012a8c0, 0x0, 0x0, 0x9)
/home/hp/src/github.com/bob96/hc34/beater/hc34.go:354 +0x2cf
github.com/bob96/hc34/beater.(*Hc34).getDateBlockHeader(0xc42012a8c0, 0xc4202d000a, 0xc, 0x0, 0x0)
/home/hp/src/github.com/bob96/hc34/beater/hc34.go:324 +0x73
github.com/bob96/hc34/beater.(*Hc34).hc34decoderfunc(0xc42012a8c0, 0xc4202d0000, 0x2d128)
/home/hp/src/github.com/bob96/hc34/beater/hc34.go:190 +0x77
github.com/bob96/hc34/beater.(*Hc34).hc34DataHolderfunc(0xc42012a8c0, 0xc420103140, 0x5e)
/home/hp/src/github.com/bob96/hc34/beater/hc34.go:141 +0xd3
github.com/bob96/hc34/beater.(*Hc34).Run(0xc42012a8c0, 0xc420142420, 0xc4201424c8, 0xb)
/home/hp/src/github.com/bob96/hc34/beater/hc34.go:105 +0x109
github.com/bob96/hc34/vendor/github.com/elastic/beats/libbeat/beat.(*Beat).launch(0xc420142420, 0x9a84c8, 0x0, 0x0)
/home/hp/src/github.com/bob96/hc34/vendor/github.com/elastic/beats/libbeat/beat/beat.go:211 +0x706
github.com/bob96/hc34/vendor/github.com/elastic/beats/libbeat/beat.Run(0x9855d5, 0x4, 0x0, 0x0, 0x9a84c8, 0xc4200001a0, 0xc4200001a0)
/home/hp/src/github.com/bob96/hc34/vendor/github.com/elastic/beats/libbeat/beat/beat.go:136 +0x65
main.main()
/home/hp/src/github.com/bob96/hc34/main.go:12 +0x54

我最初认为问题在于日期函数没有从文件中获取任何字符串,因为我们不能有一个类型为"ns"的持续时间,但我们需要在"ns"之前有一个整数,例如:"500ns"。

抱歉我放出了所有的代码,我只是不明白我的问题出在哪里。

谢谢帮助!

英文:

im working on a custum beat that decodes a binary file to extract data and send it to elasticsearch , the complication goes normaly but when i run it, it gives me a running time error of an invalid duration "ns" here is my code:

package beater
import (
&quot;fmt&quot;
&quot;io/ioutil&quot;
&quot;math&quot;
&quot;time&quot;
//&quot;log&quot;
&quot;strconv&quot;
&quot;strings&quot;
&quot;github.com/elastic/beats/libbeat/beat&quot;
&quot;github.com/elastic/beats/libbeat/common&quot;
&quot;github.com/elastic/beats/libbeat/logp&quot;
&quot;github.com/elastic/beats/libbeat/publisher&quot;
&quot;github.com/bob96/hc34/config&quot;
)
type Hc34 struct {
done   chan struct{}
config config.Config
client publisher.Client
siteKey string
fileKey string
callEndDateTime string 
callStartDateTime string
callerPartyNumber string
calledPartyNumber string
incomingTrunkKey string
outgoingTrunkKey string
blockNumber string
blockDateTime string
headerFunction int
headerUser int
callerCategory int
callerOrigineIdentity string
complementaryIdentity string 
calledDigits string 
traficType int 
serviceType int 
supportService int 
chargeDuration int 
chargeMeters int 
outgoingTrunk string
reserved string 
operatorIdentity string
operatorServiceType string
block string
filekey string
lastIndexTime time.Time
}
// Creates beater
func New(b *beat.Beat, cfg *common.Config) (beat.Beater, error) {
config := config.DefaultConfig
if err := cfg.Unpack(&amp;config); err != nil {
return nil, fmt.Errorf(&quot;Error reading config file: %v&quot;, err)
}
bt := &amp;Hc34{
done: make(chan struct{}),
config: config,
}
return bt, nil
}
func (bt *Hc34) Run(b *beat.Beat) error {
logp.Info(&quot;hc34 is running! Hit CTRL-C to stop it.&quot;)
bt.client = b.Publisher.Connect()
ticker := time.NewTicker(bt.config.Period) 
//counter := 1
for {
now := time.Now()
bt.hc34DataHolderfunc(bt.config.Path) 
bt.lastIndexTime = now             
logp.Info(&quot;Event sent&quot;)
select {
case &lt;-bt.done:
return nil
case &lt;-ticker.C:
}
/*event := common.MapStr{
&quot;@timestamp&quot;: common.Time(time.Now()),
&quot;type&quot;:       b.Name,
&quot;counter&quot;:    counter,
}
bt.client.PublishEvent(event)
logp.Info(&quot;Event sent&quot;)
counter++*/
}
}
func (bt *Hc34) Stop() {
bt.client.Close()
close(bt.done)
}
//checking error
func check(e error) {
if e != nil {
panic(e)
}
}
func (bt *Hc34) hc34DataHolderfunc(dirfile string) {    
//reading the binary file
data, err := ioutil.ReadFile(dirfile)
check(err)
//t := f.ModTime() 
bt.hc34decoderfunc(string(data))
event := common.MapStr{
&quot;@timestamp&quot;: common.Time(time.Now()),
/*&quot;siteKey&quot;: siteKey,
&quot;fileKey&quot;: fileKey,*/
//&quot;callEndDateTime&quot;:	bt.callEndDateTime,
//&quot;callStartDateTime&quot;: bt.callStartDateTime,
&quot;callerPartyNumber&quot;: bt.callerPartyNumber,
&quot;calledPartyNumber&quot;: bt.calledPartyNumber,
//&quot;incomingTrunkKey&quot;: bt.incomingTrunkKey,
//&quot;outgoingTrunkKey&quot;: bt.outgoingTrunkKey,
&quot;blockNumber&quot;: bt.blockNumber,
&quot;blockDateTime&quot;: bt.blockDateTime,
&quot;headerFunction&quot;: bt.headerFunction,
&quot;headerUser&quot;: bt.headerUser,
&quot;callerCategory&quot;: bt.callerCategory,
&quot;callerOrigineIdentity&quot;: bt.callerOrigineIdentity,
&quot;complementaryIdentity&quot;: bt.complementaryIdentity,
&quot;calledDigits&quot;: bt.calledDigits,
&quot;traficType&quot;: bt.traficType,
&quot;serviceType&quot;: bt.serviceType,
&quot;supportService&quot;: bt.supportService,
&quot;chargeDuration&quot;: bt.chargeDuration,
&quot;chargeMeters&quot;: bt.chargeMeters,
//&quot;outgoingTrunk&quot;: bt.outgoingTrunk,
&quot;reserved&quot;: bt.reserved,
&quot;peratorIdentity&quot;: bt.operatorIdentity,
&quot;operatorServiceType&quot;: bt.operatorServiceType,
}
bt.client.PublishEvent(event)
}
type hc34decoder struct{
block string
siteKey string
filekey string
}
func (bt *Hc34) hc34decoderfunc(block string){
// Get header (32 bytes) and content (1932 bytes) from block
header :=block[0:64]
content :=block[64:len(block)]
// Get block key and date time from header
blockKey :=header[4:10]
yearBlock :=header[10:12]
//BDTdecode, err := hex.DecodeString(header[10:12])
bt.blockDateTime =bt.getDate(bt.getDateBlockHeader(header[10:22]))
/*if err != nil {
log.Fatal(err)
}*/
// process content to extract CDRs
start := 0
totalCdr := len(content) / 84
for z := 0; z &lt; totalCdr; z++ {
record := content[start:start + 84]
start = start + 84
// Extract data from single record
//CEDdecode, err :=hex.DecodeString(record[10:12])
a:= hex2decimal(record[54:56])
headerFunction:= hex2decimal(record[0:2])
headerUser:= hex2decimal(record[2:4])
callerCategory:= hex2decimal(record[4:6])
callEndDateTime :=bt.getDate(bt.getDateCall(record[6:16], yearBlock))
callerOrigineIdentity:= strings.Replace(string(record[16:26]),&quot;F&quot;,&quot;&quot;,-1)
complementaryIdentity := strings.Replace(string(record[26:36]),&quot;F&quot;,&quot;&quot;,-1)
calledDigits:= strings.Replace(string(record[36:54]),&quot;F&quot;,&quot;&quot;,-1)
traficType:= hex2decimal(strings.Replace(string(a),&quot;F&quot;,&quot;&quot;,-1))
serviceType := hex2decimal(record[56:58])
supportService :=hex2decimal(record[58:60])
duration :=hex2decimal(record[60:64])
meters:= hex2decimal(record[64:70])
//outgoingTrunk :=strings.Replace(string(record[70:74]),&quot;F&quot;, &quot;&quot;,-1)
bt.reserved = record[74:78]
bt.operatorIdentity = strings.Replace(string(record[78:82]),&quot;F&quot;, &quot;&quot;,-1)
bt.operatorServiceType =record[82:84]
bt.blockNumber=blockKey
bt.callerPartyNumber = bt.getFormattedMsisdnHc34Caller(complementaryIdentity, callerOrigineIdentity)
bt.calledPartyNumber = bt.getFormattedMsisdnHc34Called(calledDigits)
bt.callStartDateTime  = bt.getStartDate(callEndDateTime, int(duration) )
/*if err !=nil{
log.Fatal(err)
}*/
bt.headerFunction=int(headerFunction)
bt.headerUser=int(headerUser)
bt.callerCategory=int(callerCategory)
bt.traficType=int(traficType)
bt.serviceType=int(serviceType)
bt.supportService=int(supportService)
bt.chargeMeters=int(meters)
bt.chargeDuration=int(duration)
func (bt *Hc34) getStartDate(endTime string, duration int) string{
layout := &quot;2006-01-02T15:04:05.000Z&quot;
t, err := time.Parse(layout, endTime)
if err!=nil{
panic(err)
}
return (t.Add(time.Duration(-duration) * time.Second)).String()
}
/**
* Get the date of the call.
* @param input the quanted date
* @param year the year
* @return the date of the call
*/
func (bt *Hc34) getDateCall(input string,year string) string{
quant:= hex2decimal(input[1:4])
hour := input[4:len(input)]
return &quot;20&quot; + year + bt.getQuantDate(quant) + &quot;&quot; + hour
}
/**
* Get date of block header.
* @param input the quanted date
* @return the date block header
*/
func(bt *Hc34) getDateBlockHeader(input string) string{
year := input[0:2]
quant:= hex2decimal(input[3:6])
hour := input[6:len(input)];
/*if err!=nil{
panic(err)
}*/
return &quot;20&quot; + year + bt.getQuantDate(quant) + &quot;&quot; + hour
}
/**
* format date.
* @param date the date
* @return the formatted date
*/
func(bt *Hc34) getDate(date string) string{
year := date[0:4]
month := date[4:6]
day := date[6:8]
hour := date[8:10]
minute := date[10:12]
second := date[12:14]
return year + &quot;-&quot; + month + &quot;-&quot; + day + &quot; &quot; + hour + &quot;:&quot; + minute + &quot;:&quot; + second;
}
/**
* Format quanted date.
* @param quant the quanted date
* @return the formatted date
*/
func(bt *Hc34) getQuantDate(quant int) string{
nanoDayOfYear:=string(quant*24*60*60*1000*1000*1000) + &quot;ns&quot;
durt,err:=time.ParseDuration(nanoDayOfYear)
t := time.Date(2009, time.January, 01, 00, 0, 0, 0, time.UTC)
t=t.Add(durt)
if err!=nil{
panic(err)
}
return string(t.Month())+&quot;&quot;+string(t.Day())
}
func bin(i int, prefix bool) string {
i64 := int64(i)
if prefix {
return &quot;0b&quot; + strconv.FormatInt(i64, 2) // base 2 for binary
} else {
return strconv.FormatInt(i64, 2) // base 2 for binary
}
}
func bin2int(binStr string) int {
// base 2 for binary
result, _ := strconv.ParseInt(binStr, 2, 64)
return int(result)
}
func hex(i int, prefix bool) string {
i64 := int64(i)
if prefix {
return &quot;0x&quot; + strconv.FormatInt(i64, 16) // base 16 for hexadecimal
} else {
return strconv.FormatInt(i64, 16) // base 16 for hexadecimal
}
}
func hex2int(hexStr string) int {
// base 16 for hexadecimal
result, _ := strconv.ParseInt(hexStr, 16, 64)
return int(result)
}
func hex2decimal(hexStr string) int{
base16 := 16;
var val float64
for i:=0; i&gt;len(hexStr);i++{
vala:=hex2int(string(base16))
valo:=hex2int(string(hexStr[len(hexStr)-i]))
val+=float64(valo)*math.Pow(float64(vala),float64(i))
}
return int(val)
}

and here its the error that i have :

panic: time: invalid duration ns
goroutine 1 [running]:
github.com/bob96/hc34/beater.(*Hc34).getQuantDate(0xc42012a8c0, 0x0, 0x0, 0x9)
/home/hp/src/github.com/bob96/hc34/beater/hc34.go:354 +0x2cf
github.com/bob96/hc34/beater.(*Hc34).getDateBlockHeader(0xc42012a8c0, 0xc4202d000a, 0xc, 0x0, 0x0)
/home/hp/src/github.com/bob96/hc34/beater/hc34.go:324 +0x73
github.com/bob96/hc34/beater.(*Hc34).hc34decoderfunc(0xc42012a8c0, 0xc4202d0000, 0x2d128)
/home/hp/src/github.com/bob96/hc34/beater/hc34.go:190 +0x77
github.com/bob96/hc34/beater.(*Hc34).hc34DataHolderfunc(0xc42012a8c0, 0xc420103140, 0x5e)
/home/hp/src/github.com/bob96/hc34/beater/hc34.go:141 +0xd3
github.com/bob96/hc34/beater.(*Hc34).Run(0xc42012a8c0, 0xc420142420, 0xc4201424c8, 0xb)
/home/hp/src/github.com/bob96/hc34/beater/hc34.go:105 +0x109
github.com/bob96/hc34/vendor/github.com/elastic/beats/libbeat/beat.(*Beat).launch(0xc420142420, 0x9a84c8, 0x0, 0x0)
/home/hp/src/github.com/bob96/hc34/vendor/github.com/elastic/beats/libbeat/beat/beat.go:211 +0x706
github.com/bob96/hc34/vendor/github.com/elastic/beats/libbeat/beat.Run(0x9855d5, 0x4, 0x0, 0x0, 0x9a84c8, 0xc4200001a0, 0xc4200001a0)
/home/hp/src/github.com/bob96/hc34/vendor/github.com/elastic/beats/libbeat/beat/beat.go:136 +0x65
main.main()
/home/hp/src/github.com/bob96/hc34/main.go:12 +0x54

what i thought in the first place is that the date functions don't get any string from the file, because we can't have a duration type "ns" but we need to have an integer before "ns" like so : "500ns".

sorry if i put out all the code i just didn't understand where exectly is my problem.

thanks for helping me!

答案1

得分: -1

这一行看起来有问题:

nanoDayOfYear:=string(quant*24*60*60*1000*1000*1000) + "ns"

具体来说,string(...) 不会得到你想要的结果。你可能想要将那个数字转换为十进制字符串。可以尝试使用以下代码替代:

nanoDayOfYear:=strconv.FormatInt(quant*24*60*60*1000*1000*1000, 10) + "ns"
英文:

This line looks problematic:

nanoDayOfYear:=string(quant*24*60*60*1000*1000*1000) + &quot;ns&quot;

Specifically, string(...) doesn't do what you want. Presumably you want to convert that number to a base-10 string. Try this instead:

nanoDayOfYear:=strconv.FormatInt(quant*24*60*60*1000*1000*1000, 10) + &quot;ns&quot;

huangapple
  • 本文由 发表于 2017年8月4日 15:14:45
  • 转载请务必保留本文链接:https://go.coder-hub.com/45500420.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定