[go-nuts] Re: Table driven tests and error/output testing

2020-10-19 Thread Tamás Gulácsi
Use bytes.Buffer or strings.Builder directly - no need for the bufio.Writer.
bufio.Writer only speeds up writing by calling the underlying Writer less, 
with bigger slices.
Here you Write into a memory, just as bufio.Writer.

Also, you can save some allocations by creating the buffer once outside of 
the loop,
and Reset() it in each cycle before calling handleCommand.


amits...@gmail.com a következőt írta (2020. október 20., kedd, 6:03:31 
UTC+2):

> Hi all, Consider the following test configuration:
>
>
> func TestHandleCommand(t *testing.T) {
>
> type expectedResult struct {
> output string
> err error
> }
> type testConfig struct {
> args []string
> result expectedResult
> }
>
> testConfigs := []testConfig{
> testConfig{
> args: []string{"-h"},
> result: expectedResult{
> err: nil,
> output: `Expected output`,
> },
> },
> }
>
> Then, I do this:
>
>
> for _, tc := range testConfigs {
> byteBuf := new(bytes.Buffer)
> w := bufio.NewWriter(byteBuf)
>
> err := handleCommand(w, tc.args)
> if tc.result.err == nil && err != nil {
> t.Errorf("Expected nil error, got %v", err)
> }
>
> if tc.result.err != nil && err.Error() != tc.result.err.Error() {
> t.Errorf("Expected error %v, got %v", tc.result.err, err)
> }
>
> if len(tc.result.output) != 0 {
> w.Flush()
> gotOutput := byteBuf.String()
> if tc.result.output != gotOutput {
> t.Errorf("Expected output to be: %v, Got: %v",
> tc.result.output, gotOutput)
> }
> }
> }
> }
>
> The above pattern works for me since the function may return an error
> and/or it may have something it writes to the provided writer, w.
>
> Is there a more concise way to write this?
>
>
>
> Thanks,
> Amit.
>

-- 
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 golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/2759fea4-a3d6-42ee-b3e4-2c0ac208f2b9n%40googlegroups.com.


Re: [go-nuts] gccgo problem compiling go from source

2020-10-19 Thread gerritbinnenmars
Hello Ian,Thanks for the quick reaction. It seems my request was not clear.What 
I am doing is the other way around: using gccgo to build the "go" cmd.So clone 
the "go" source from github and then go build -compiler gccgo ./cmd/goGerrit
 Oorspronkelijk bericht Van: Ian Lance Taylor  
Datum: 20-10-20  04:25  (GMT+01:00) Aan: Gerrit Binnenmars 
 Cc: golang-nuts  
Onderwerp: Re: [go-nuts] gccgo problem compiling go from source On Mon, Oct 19, 
2020 at 2:06 PM Gerrit Binnenmars wrote:>> I used 
crosstool-ng successfully to build a go compiler for ppc e500.> Unfortunately 
go build does not support ppc therefore go needs to be> build from source using 
the amd64 gccgo compiler that I also build> with crosstool-ng.>> Compiling go 
from source fails:> Problem: undefined name stdpkg in 
internal/goroot/gccgo.go>> I included the output of my build script below. Any 
help or tips are welcome.>> With kind regards,>> Gerrit Binnenmars>> Info:> 
This is crosstool-NG version 1.24.0.191_364ed7a> GO111MODULE=""> 
GOARCH="amd64"> GOBIN=""> GOCACHE="/home/maintain/.cache/go-build"> 
GOENV="/home/maintain/.config/go/env"> GOEXE=""> GOFLAGS=""> 
GOHOSTARCH="amd64"> GOHOSTOS="linux"> GOINSECURE=""> 
GOMODCACHE="/home/maintain/gonew/pkg/mod"> GONOPROXY=""> GONOSUMDB=""> 
GOOS="linux"> GOPATH="/home/maintain/gonew"> GOPRIVATE=""> 
GOPROXY="https://proxy.golang.org,direct;> 
GOROOT="/home/maintain/x-tools/x86_64-e500-linux-gnu/x86_64-e500-linux-gnu/sysroot/lib">
 GOSUMDB="sum.golang.org"> GOTMPDIR=""> 
GOTOOLDIR="/home/maintain/x-tools/x86_64-e500-linux-gnu/x86_64-e500-linux-gnu/sysroot/lib/pkg/tool/linux_amd64">
 GCCGO="/home/maintain/x-tools/x86_64-e500-linux-gnu/bin/gccgo"> AR="ar"> 
CC="/home/maintain/x-tools/x86_64-e500-linux-gnu/bin/gcc"> 
CXX="/home/maintain/x-tools/x86_64-e500-linux-gnu/bin/g++"> CGO_ENABLED="1"> 
GOMOD=""> 
CGO_CFLAGS="--with-sysroot=/home/maintain/x-tools/x86_64-e500-linux-gnu/x86_64-e500-linux-gnu/sysroot">
 CGO_CPPFLAGS=""> CGO_CXXFLAGS="-g -O2"> CGO_FFLAGS="-g -O2"> CGO_LDFLAGS="-g 
-O2"> PKG_CONFIG="pkg-config"> GOGCCFLAGS="-fPIC -m64 -pthread 
-fmessage-length=0> -fdebug-prefix-map=/tmp/go-build355977706=/tmp/go-build> 
-gno-record-gcc-switches"> go version go1.15.2 linux/amd64> gccgo (GCC) 10.2.0> 
Copyright (C) 2020 Free Software Foundation, Inc.> This is free software; see 
the source for copying conditions.  There is NO> warranty; not even for 
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.>> 
WORK=/tmp/go-build273889551> mkdir -p $WORK/b100/> cd $WORK> 
/home/maintain/x-tools/x86_64-e500-linux-gnu/bin/gccgo> 
-fgo-importcfg=/dev/null -c -x c - -o /dev/null || true> cd 
/home/maintain/gonew/src/internal/goroot> 
/home/maintain/x-tools/x86_64-e500-linux-gnu/bin/gccgo -c -g -m64> 
-fdebug-prefix-map=$WORK=/tmp/go-build -gno-record-gcc-switches> 
-fgo-pkgpath=internal/goroot -o $WORK/b100/_go_.o -I> 
$WORK/b100/_importcfgroot_ ./gccgo.go> mkdir -p $WORK/b027/> mkdir -p 
$WORK/b027/_importcfgroot_/cmd/go/internal> ln -s 
/home/maintain/.cache/go-build/ad/ade44815e7af8b7305b2db4099ec5b08aafcbd6e374a2c13d8e99c2986ca93c6-d>
 $WORK/b027/_importcfgroot_/cmd/go/internal/libauth.a> ln -s 
/home/maintain/.cache/go-build/d2/d26f05f163d86aecfadfbb952dfef9a314aa1c84c23fddd39bce127ccc85d101-d>
 $WORK/b027/_importcfgroot_/cmd/go/internal/libcfg.a> mkdir -p 
$WORK/b027/_importcfgroot_/cmd/internal> ln -s 
/home/maintain/.cache/go-build/2f/2f6811b0804c481edbfd9952d1aac22414f84ee1aec229218b03956bf3f9aa7a-d>
 $WORK/b027/_importcfgroot_/cmd/internal/libbrowser.a> cd 
/home/maintain/gonew/src/cmd/go/internal/web> 
/home/maintain/x-tools/x86_64-e500-linux-gnu/bin/gccgo -c -g -m64> 
-fdebug-prefix-map=$WORK=/tmp/go-build -gno-record-gcc-switches> 
-fgo-pkgpath=cmd/go/internal/web -o $WORK/b027/_go_.o -I> 
$WORK/b027/_importcfgroot_ ./api.go ./http.go ./url.go ./url_other.go> # 
internal/goroot> src/internal/goroot/gccgo.go:24:10: error: reference to 
undefined name 'stdpkg'>    24 |   return stdpkg[path]>   |  ^> # 
cmd/go/internal/web> src/cmd/go/internal/web/api.go:92:45: error: reference to 
undefined> field or method 'Redacted'>    92 |   return nil, 
fmt.Errorf("reading %s: %v", u.Redacted(), err)It looks like you are using the 
"go" program to build the gccgostandard library.  That doesn't work.  The gccgo 
standard library mustbe built as part of GCC, using the usual configure/make 
commands usedto build GCC itself.  When configuring GCC, use 
--enable-languages=go.Ian

-- 
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 golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/5f8e657e.1c69fb81.3e6dc.0cf4%40mx.google.com.


Re: [go-nuts] Positional arguments and flag package

2020-10-19 Thread Amit Saha
On Thu, Oct 15, 2020 at 4:27 PM Roland Müller  wrote:
>
> Actually, it's explicitly documented, so I don't have to guess:
> https://golang.org/pkg/flag/#hdr-Command_line_flag_syntax

Thank you. I read it and it makes sense why the behavior is like that.

>
>
> Am Do., 15. Okt. 2020 um 08:22 Uhr schrieb Roland Müller :
>>
>> I guess it's usage of flag is meant in to behave like parsing flags in 
>> Unix/LInux, or Python' argparse:
>>
>> after the command you have the flags denoted by '-'
>> after flags follow rest of command line args where elements can be every 
>> character string
>>
>> BR,
>> Roland
>>
>> Am Fr., 9. Okt. 2020 um 07:10 Uhr schrieb Amit Saha :
>>>
>>> Hi all, I realize that the flag package stops parsing os.Args[] once it 
>>> finds a non "-" character. This means, if I invoke my program as:
>>>
>>> $ ./myprog arg1 -d value
>>>
>>> flag.Parse() will stop parsing the moment it sees arg1 and result in NArg() 
>>> returning 2 instead of 1.
>>>
>>> Is there a recommended workaround to handle both $./myprog -d value arg1 
>>> and $./myprog arg1 -d value correctly?
>>>
>>> Thanks for any suggestions.
>>>
>>> Thanks,
>>> Amit.
>>>
>>> --
>>> 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 golang-nuts+unsubscr...@googlegroups.com.
>>> To view this discussion on the web visit 
>>> https://groups.google.com/d/msgid/golang-nuts/d1399079-4589-454f-91d3-820a60aa239dn%40googlegroups.com.

-- 
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 golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CANODV3nDeOQK%3DOkPMXtMuSQpkKkvLLG7NjO%3D9AJ60_QMvjc%3DfQ%40mail.gmail.com.


[go-nuts] Table driven tests and error/output testing

2020-10-19 Thread Amit Saha
Hi all, Consider the following test configuration:


func TestHandleCommand(t *testing.T) {

type expectedResult struct {
output string
errerror
}
type testConfig struct {
args   []string
result expectedResult
}

testConfigs := []testConfig{
testConfig{
args: []string{"-h"},
result: expectedResult{
err: nil,
output: `Expected output`,
},
},
}

Then, I do this:


for _, tc := range testConfigs {
byteBuf := new(bytes.Buffer)
w := bufio.NewWriter(byteBuf)

err := handleCommand(w, tc.args)
if tc.result.err == nil && err != nil {
t.Errorf("Expected nil error, got %v", err)
}

if tc.result.err != nil && err.Error() != tc.result.err.Error() {
t.Errorf("Expected error %v, got %v", tc.result.err, err)
}

if len(tc.result.output) != 0 {
w.Flush()
gotOutput := byteBuf.String()
if tc.result.output != gotOutput {
t.Errorf("Expected output to be: %v, Got: %v",
tc.result.output, gotOutput)
}
}
}
}

The above pattern works for me since the function may return an error
and/or it may have something it writes to the provided writer, w.

Is there a more concise way to write this?



Thanks,
Amit.

-- 
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 golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CANODV3%3DsOA4FKakaQ0mrcC%3D-BnVNq8SdnvDHgXShmrRt-_upHw%40mail.gmail.com.


Re: [go-nuts] gccgo problem compiling go from source

2020-10-19 Thread Ian Lance Taylor
On Mon, Oct 19, 2020 at 2:06 PM Gerrit Binnenmars
 wrote:
>
> I used crosstool-ng successfully to build a go compiler for ppc e500.
> Unfortunately go build does not support ppc therefore go needs to be
> build from source using the amd64 gccgo compiler that I also build
> with crosstool-ng.
>
> Compiling go from source fails:
> Problem: undefined name stdpkg in internal/goroot/gccgo.go
>
> I included the output of my build script below. Any help or tips are welcome.
>
> With kind regards,
>
> Gerrit Binnenmars
>
> Info:
> This is crosstool-NG version 1.24.0.191_364ed7a
> GO111MODULE=""
> GOARCH="amd64"
> GOBIN=""
> GOCACHE="/home/maintain/.cache/go-build"
> GOENV="/home/maintain/.config/go/env"
> GOEXE=""
> GOFLAGS=""
> GOHOSTARCH="amd64"
> GOHOSTOS="linux"
> GOINSECURE=""
> GOMODCACHE="/home/maintain/gonew/pkg/mod"
> GONOPROXY=""
> GONOSUMDB=""
> GOOS="linux"
> GOPATH="/home/maintain/gonew"
> GOPRIVATE=""
> GOPROXY="https://proxy.golang.org,direct;
> GOROOT="/home/maintain/x-tools/x86_64-e500-linux-gnu/x86_64-e500-linux-gnu/sysroot/lib"
> GOSUMDB="sum.golang.org"
> GOTMPDIR=""
> GOTOOLDIR="/home/maintain/x-tools/x86_64-e500-linux-gnu/x86_64-e500-linux-gnu/sysroot/lib/pkg/tool/linux_amd64"
> GCCGO="/home/maintain/x-tools/x86_64-e500-linux-gnu/bin/gccgo"
> AR="ar"
> CC="/home/maintain/x-tools/x86_64-e500-linux-gnu/bin/gcc"
> CXX="/home/maintain/x-tools/x86_64-e500-linux-gnu/bin/g++"
> CGO_ENABLED="1"
> GOMOD=""
> CGO_CFLAGS="--with-sysroot=/home/maintain/x-tools/x86_64-e500-linux-gnu/x86_64-e500-linux-gnu/sysroot"
> CGO_CPPFLAGS=""
> CGO_CXXFLAGS="-g -O2"
> CGO_FFLAGS="-g -O2"
> CGO_LDFLAGS="-g -O2"
> PKG_CONFIG="pkg-config"
> GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0
> -fdebug-prefix-map=/tmp/go-build355977706=/tmp/go-build
> -gno-record-gcc-switches"
> go version go1.15.2 linux/amd64
> gccgo (GCC) 10.2.0
> Copyright (C) 2020 Free Software Foundation, Inc.
> This is free software; see the source for copying conditions.  There is NO
> warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
>
> WORK=/tmp/go-build273889551
> mkdir -p $WORK/b100/
> cd $WORK
> /home/maintain/x-tools/x86_64-e500-linux-gnu/bin/gccgo
> -fgo-importcfg=/dev/null -c -x c - -o /dev/null || true
> cd /home/maintain/gonew/src/internal/goroot
> /home/maintain/x-tools/x86_64-e500-linux-gnu/bin/gccgo -c -g -m64
> -fdebug-prefix-map=$WORK=/tmp/go-build -gno-record-gcc-switches
> -fgo-pkgpath=internal/goroot -o $WORK/b100/_go_.o -I
> $WORK/b100/_importcfgroot_ ./gccgo.go
> mkdir -p $WORK/b027/
> mkdir -p $WORK/b027/_importcfgroot_/cmd/go/internal
> ln -s 
> /home/maintain/.cache/go-build/ad/ade44815e7af8b7305b2db4099ec5b08aafcbd6e374a2c13d8e99c2986ca93c6-d
> $WORK/b027/_importcfgroot_/cmd/go/internal/libauth.a
> ln -s 
> /home/maintain/.cache/go-build/d2/d26f05f163d86aecfadfbb952dfef9a314aa1c84c23fddd39bce127ccc85d101-d
> $WORK/b027/_importcfgroot_/cmd/go/internal/libcfg.a
> mkdir -p $WORK/b027/_importcfgroot_/cmd/internal
> ln -s 
> /home/maintain/.cache/go-build/2f/2f6811b0804c481edbfd9952d1aac22414f84ee1aec229218b03956bf3f9aa7a-d
> $WORK/b027/_importcfgroot_/cmd/internal/libbrowser.a
> cd /home/maintain/gonew/src/cmd/go/internal/web
> /home/maintain/x-tools/x86_64-e500-linux-gnu/bin/gccgo -c -g -m64
> -fdebug-prefix-map=$WORK=/tmp/go-build -gno-record-gcc-switches
> -fgo-pkgpath=cmd/go/internal/web -o $WORK/b027/_go_.o -I
> $WORK/b027/_importcfgroot_ ./api.go ./http.go ./url.go ./url_other.go
> # internal/goroot
> src/internal/goroot/gccgo.go:24:10: error: reference to undefined name 
> 'stdpkg'
>24 |   return stdpkg[path]
>   |  ^
> # cmd/go/internal/web
> src/cmd/go/internal/web/api.go:92:45: error: reference to undefined
> field or method 'Redacted'
>92 |   return nil, fmt.Errorf("reading %s: %v", u.Redacted(), err)

It looks like you are using the "go" program to build the gccgo
standard library.  That doesn't work.  The gccgo standard library must
be built as part of GCC, using the usual configure/make commands used
to build GCC itself.  When configuring GCC, use --enable-languages=go.

Ian

-- 
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 golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CAOyqgcWDf5AAGRgsreZYK14y6bTa7swdn1HjjM4RDGWeb8tH8w%40mail.gmail.com.


Re: [go-nuts] schedule a job executing in future

2020-10-19 Thread Uday Kiran Jonnala
For the same scenario, we use the following
- Go cron to schedule the job execution
- For crash consistency of the program, use a DB (as mentioned by Jasper 
also) with a db entry for job schedule information.


On Monday, October 19, 2020 at 2:33:50 AM UTC-7 jesper.lou...@gmail.com 
wrote:

> On Mon, Oct 19, 2020 at 9:51 AM Zhihong GUO  wrote:
>
>>
>> I am implementing a reminder system. The purpose is to provide API to 
>> client App to add a meeting, and before X minutes the meeting is to open, 
>> the reminder system can send notif to user by SMS or email. Here I need a 
>> function like: when a meeting is created, check the open time of the 
>> meeting, and schedule a job of sending email or sms to be executed just 
>> before the X minutes the meeting is open. I checked the goworker but it 
>> seems there is no way to enqueue a "delayed" job, any suggestions about the 
>> implementation?
>>
>>
> Not knowing your design criteria, I'm just going to make some assumptions 
> along the way:
>
> I'd use a database, probably postgresql. It should serve you up to at 
> least something like 100k concurrent meetings managed at any point in time. 
> It'll break apart at an even larger scale, but chances are you can rewrite 
> with new knowledge if that ever happens. You simply have a table tracking 
> the interval of each meeting and you can use this information for a lot of 
> things, including guarding for meeting conflicts and so on. On the Go side, 
> you have a job ticker (time.NewTicker(time.Minute)) and once it fires, you 
> look in the database if any meeting is about to start. Postgresql generally 
> handles time/date information well enough that you can use its internal 
> management to quickly query the eligible meetings. You can then decide if 
> you want to throw them on a channel internally and have another part of the 
> system responsible for sending out the emails, or if you want to do it in 
> the job ticker loop. I'd probably go with the former because you can have a 
> channel for each transport method you have (SMS, Email, Cloud Messaging[1], 
> etc)
>
> In turn, the Go part of the system simply reacts to events on channels and 
> carries out the work. The scheduling parts are handled by the database. I 
> think this is a nice split of responsibility in the system, since it will 
> simplify both parts: the database doesn't know about transports and their 
> design, and the Go system doesn't have to worry about long-term persistence 
> of meetings.
>
> Rationale:
>
> * Databases can survive a system reboot or an application restart. You 
> probably want your meetings persistent. And you want your meetings to be 
> stored in a way such that you don't accidentally lose them.
> * It is a rather simple poll-solution which is fast provided you have the 
> right indexes created on the database side.
> * You can use a partial index, created over meetings for which you have 
> yet to send out notifications. This severely cuts the index size down.
> * One-shot notifications are probably ok for a 10 minute window. If they 
> fail to arrive, they are not important in less than 10 minutes.
> * The relational model is quite strong if you don't know where you are 
> going in the long run as it tends to ensure good bounds on most queries. As 
> you learn more about your problem, you can look into switching once your 
> database reaches a pain threshold (Which is a couple of terabytes for 
> Postgres, at the very least).
>
> Alternative:
>
> Use a database, but Go (Hah!) with a more cloud-DBesque solution. This 
> could open up for almost infinite scaling, but often has a linear cost with 
> the size of your database and your query rate.
>
> [1] Consider Google's FCM solution or something similar for this route. 
> They demux the handling of different device types and transports for you, 
> as well as handle token refreshing, canonical token updates and so on for 
> you. It makes life much easier for everyone if you don't have to struggle 
> with the transport-specific APIs.
>
>

-- 
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 golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/d580cdbb-3e3a-48d6-bcde-5cf5b27366fen%40googlegroups.com.


[go-nuts] gccgo problem compiling go from source

2020-10-19 Thread Gerrit Binnenmars
Hello,

I used crosstool-ng successfully to build a go compiler for ppc e500.
Unfortunately go build does not support ppc therefore go needs to be
build from source using the amd64 gccgo compiler that I also build
with crosstool-ng.

Compiling go from source fails:
Problem: undefined name stdpkg in internal/goroot/gccgo.go

I included the output of my build script below. Any help or tips are 
welcome.

With kind regards,

Gerrit Binnenmars

Info:
This is crosstool-NG version 1.24.0.191_364ed7a
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/maintain/.cache/go-build"
GOENV="/home/maintain/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/maintain/gonew/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/maintain/gonew"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct;
GOROOT="/home/maintain/x-tools/x86_64-e500-linux-gnu/x86_64-e500-linux-gnu/sysroot/lib"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/home/maintain/x-tools/x86_64-e500-linux-gnu/x86_64-e500-linux-gnu/sysroot/lib/pkg/tool/linux_amd64"
GCCGO="/home/maintain/x-tools/x86_64-e500-linux-gnu/bin/gccgo"
AR="ar"
CC="/home/maintain/x-tools/x86_64-e500-linux-gnu/bin/gcc"
CXX="/home/maintain/x-tools/x86_64-e500-linux-gnu/bin/g++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="--with-sysroot=/home/maintain/x-tools/x86_64-e500-linux-gnu/x86_64-e500-linux-gnu/sysroot"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0
-fdebug-prefix-map=/tmp/go-build355977706=/tmp/go-build
-gno-record-gcc-switches"
go version go1.15.2 linux/amd64
gccgo (GCC) 10.2.0
Copyright (C) 2020 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

WORK=/tmp/go-build273889551
mkdir -p $WORK/b100/
cd $WORK
/home/maintain/x-tools/x86_64-e500-linux-gnu/bin/gccgo
-fgo-importcfg=/dev/null -c -x c - -o /dev/null || true
cd /home/maintain/gonew/src/internal/goroot
/home/maintain/x-tools/x86_64-e500-linux-gnu/bin/gccgo -c -g -m64
-fdebug-prefix-map=$WORK=/tmp/go-build -gno-record-gcc-switches
-fgo-pkgpath=internal/goroot -o $WORK/b100/_go_.o -I
$WORK/b100/_importcfgroot_ ./gccgo.go
mkdir -p $WORK/b027/
mkdir -p $WORK/b027/_importcfgroot_/cmd/go/internal
ln -s 
/home/maintain/.cache/go-build/ad/ade44815e7af8b7305b2db4099ec5b08aafcbd6e374a2c13d8e99c2986ca93c6-d
$WORK/b027/_importcfgroot_/cmd/go/internal/libauth.a
ln -s 
/home/maintain/.cache/go-build/d2/d26f05f163d86aecfadfbb952dfef9a314aa1c84c23fddd39bce127ccc85d101-d
$WORK/b027/_importcfgroot_/cmd/go/internal/libcfg.a
mkdir -p $WORK/b027/_importcfgroot_/cmd/internal
ln -s 
/home/maintain/.cache/go-build/2f/2f6811b0804c481edbfd9952d1aac22414f84ee1aec229218b03956bf3f9aa7a-d
$WORK/b027/_importcfgroot_/cmd/internal/libbrowser.a
cd /home/maintain/gonew/src/cmd/go/internal/web
/home/maintain/x-tools/x86_64-e500-linux-gnu/bin/gccgo -c -g -m64
-fdebug-prefix-map=$WORK=/tmp/go-build -gno-record-gcc-switches
-fgo-pkgpath=cmd/go/internal/web -o $WORK/b027/_go_.o -I
$WORK/b027/_importcfgroot_ ./api.go ./http.go ./url.go ./url_other.go
# internal/goroot
src/internal/goroot/gccgo.go:24:10: error: reference to undefined name 
'stdpkg'
   24 |   return stdpkg[path]
  |  ^
# cmd/go/internal/web
src/cmd/go/internal/web/api.go:92:45: error: reference to undefined
field or method 'Redacted'
   92 |   return nil, fmt.Errorf("reading %s: %v", u.Redacted(), err)  

-- 
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 golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/10e6c037-e755-4e58-a4c8-7f5cd8fde2e7n%40googlegroups.com.


Re: [go-nuts] net/http TLS issue

2020-10-19 Thread Rich
Thanks for your reply. I think I have it down now. What I am going to do 
is: 
1. Read the key in to pemBlk
2. See if it's got a passcode
3. If it does decrypt
```
if x509.IsEncryptedPEMBlock(pemBlk) {
keyPEMBlock, err = x509.DecryptPEMBlock(pemBlk, []byte(passphrase))
```

As to having to have a human enter the passcode on each restart. I have a 
json configuration file that contains directives for where the keypair is 
an the passphrase. Read the passcode, try to decrypt it.  If the decrypt 
fails -- its probably in clear text so encrypt it and write it back to the 
config file. This way all the person has to do is put the passphrase in 
clear text, restart application, password is now encrypted in the config 
file. When the password changes because the key changed (once a year), 
change the config (plaintext) and restart -- passphrase is then encrypted. 
 
On Sunday, October 18, 2020 at 9:01:23 PM UTC-4 pat2...@gmail.com wrote:

> On Sunday, October 18, 2020 at 4:39:46 PM UTC-4 Rich wrote:
>
>> I have no problem writing this myself and I already have ideas on what I 
>> am going to do, but before I do that I thought I'd ask and see if anyone 
>> knew of a package, or some easier way that did this already. I've spent 
>> hours in the past writing code only to find later someone has written a 
>> great package that does what I need and more. Never hurts to ask right ;
>>
>
> The great packages have been written. But the real solution is to use a 
> service either in software like AWS Secrets Manager or in a hardware box 
> like the banking networks like.  If your company has had this policy a long 
> time, use whatever other systems have used. 
>
> Writing crypto software that seems to work is not hard. For this case, 
> have the operator enter a passphrase, run it thru a HMAC, and then use AES 
> 256 to encipher/decipher the CERT. Store the binary in some standard 
> format, try to avoid ANS.1 if you can possibly do it.
>
> Writing crypto software that really works, is secure, etc. is very hard. 
> No offense, but you are unlikely to do it.
>
> I don't understand how this is supposed to work. Do you ask the system's 
> operator to type in the passphrase every time the service is restarted? 
> Most modern systems don't have a human operator to do such typing. And how 
> do you ensure that there is no keyboard logger on the operator's terminal? 
> Or are you keeping the passphrase in someplace like an environment variable 
> or a secret file?
>
> The software and the crypto are only a tiny part of the issue. Either do 
> whatever made them happy in the past, or find out what is really driving 
> this "requirement".
>

-- 
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 golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/a6279a0d-63e6-4c2d-8047-cd7c7905956dn%40googlegroups.com.


Re: [go-nuts] Re: implementing macro in plan 9 assembly

2020-10-19 Thread Diego Joss
Have a look at https://golang.org/doc/asm
and examples are always a good source of inspiration. For example
https://golang.org/src/math/dim.go at line 35 defines the prototype for
function Max, which is implemented in assembly in
https://golang.org/src/math/dim_amd64.s

-- Diego

On Fri, 16 Oct 2020 at 14:38, saurav deshpande <
saurav.deshpande1...@gmail.com> wrote:

> okay, Thank you
>
> On Friday, October 16, 2020 at 6:06:34 PM UTC+5:30 iko...@gmail.com wrote:
>
>> I think you can use nasm assembly through inline ASM in cgo indirectly...
>> Go supports writing .s-files written in Go's internal assembly format,
>> which should be much faster than cgo to compile and is probably preferable,
>> but needs a bit of learning.
>>
>>   *Joop Kiefte* - Chat @ Spike
>> 
>> [image: q9zcd]
>>
>> On October 16, 2020 at 12:30 GMT, saurav deshpande <
>> saurav.des...@gmail.com> wrote:
>>
>> So, is it possible to define functions declared in go and defined in nasm
>> assembly? If yes then can you please share an example.
>>
>> Thank you
>>
>> On Friday, October 16, 2020 at 5:39:33 PM UTC+5:30 iko...@gmail.com
>> wrote:
>>
>>> I don't know how this should actually be done, but remember that the Go
>>> assembly is not actually Plan 9 assembly, it's an abstraction by itself,
>>> meant for internal use first and foremost.
>>>
>>>   *Joop Kiefte* - Chat @ Spike
>>>  [image:
>>> q9y39]
>>>
>>> On October 16, 2020 at 10:20 GMT, saurav deshpande <
>>> saurav.des...@gmail.com> wrote:
>>>
>>>
>>> Thank you for the reply.
>>> I do not understand, actually I am trying to define the fuctions in
>>> plan9 assembly  whoes declaration is done in a go file. I want to use macro
>>> like the macro in nasm, but couldn't understand how to do it.
>>> It would be very helpful if you could give an example.
>>>
>>> Thank you.
>>>
>>>
>>> On Friday, October 16, 2020 at 12:07:23 AM UTC+5:30 al...@pbrane.org
>>> wrote:
>>>
 saurav deshpande  once said:
 > How to implement macro in plan9 assembly? I read the documentation of
 > plan9 assembly but could not find it. Is there any alternative for
 > macro in plan9?

 Assembly language source files are preprocessed just like C source.
 The familiar #define and #include directives should work as expected.

 Anthony

>>> --
>>> 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 golang-nuts...@googlegroups.com.
>>> To view this discussion on the web visit
>>> https://groups.google.com/d/msgid/golang-nuts/c779e51f-ff41-4686-a843-0830316383c3n%40googlegroups.com
>>> 
>>> .
>>>
>>> --
>> 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 golang-nuts...@googlegroups.com.
>>
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/golang-nuts/79b37153-fcc1-4a5f-85ea-6127d28465d8n%40googlegroups.com
>> 
>> .
>>
>> --
> 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 golang-nuts+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/golang-nuts/f1170b24-bcbe-4e2c-8f91-2f992d810203n%40googlegroups.com
> 
> .
>

-- 
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 golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CAGjxhK%3D20mUXCQboVNNXUosTyxZggitC-bJ%3D%2BMhvLs-x0pk26Q%40mail.gmail.com.


[go-nuts] Openings for Golang backend engineers at Kawa Space

2020-10-19 Thread Kalpana SR








*At Kawa Space, we’re a super crazy bunch, building the future of how 
space-based solutions are provisioned and  consumed at scale; We are a 
small bunch of geeks who are interested in writing code, passionate about 
building systems, curious in analyzing images from space and dedicated to 
bringing insights from space to people on earth who need them.We are 
looking for a super geek to join us in our mission by Building out our 
backend systems primarily in Golang.We are looking for someone with 1 - 
3yrs experience who can work effectively in a remote team.Key 
Responsibilities - Design and develop systems that need no maintenance (are 
you willing to dream?)- Maintain and develop a service-oriented backend 
(with great power comes great responsibility)  - Analyze and identify 
bottlenecks in performance (and not be a pain in the neck in the 
meantime)  - Design secure, stable, and robust architecture (if you build a 
stupid one, you will need to maintain it so…)  - Improve monitoring of 
production services to catch warning signs and critical conditions 
(clairvoyance is a bonus)- Collaborate with front-end engineers to add 
support for complex user interfaces  (or write it yourself)- Collaborate 
with DevOps to automate everything. (added plus if you can automate writing 
the code as well)  Skills  - Golang with preferable experience in 
Python.  - PostgreSQL  - Redis, kafka, Docker (would be nice)  - Good to 
have - Experience in Ruby On Rails.  For more information email us on 
talent@kawa.space*
-- 
STATEMENT OF CONFIDENTIALITY: This email message, including any 
attachments, is for the sole use of the intended recipient(s) and may 
include privileged or otherwise confidential information. Any unauthorized 
review, forwarding, printing, copying, use, disclosure or distribution is 
strictly prohibited and may be unlawful. If you received this message in 
error, or have reason to believe you are not the intended recipient, please 
contact the sender by reply email and destroy all copies of the original 
message.

-- 
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 golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/275b7b78-50eb-467c-a82b-edb5d391022bn%40googlegroups.com.


[go-nuts] protoc-gen-go uses deprecated libraries

2020-10-19 Thread bsr

Hello,

I am coming back to a project after few months, and there has been changes 
to the protobuf libraries. I read the blog post, and docs followed the 
instructions 
 
to install and use the library. Please see the below header of the 
generated code.
I uses the latest library version, but it still include older versions. I 
was expecting

github.com/golang/protobuf/proto -> 
google.golang.org/protobuf/proto

github.com/golang/protobuf/ptypes/timestamp -> 
google.golang.org/protobuf/types/known/timestamppb

etc.

what am I missing?

```
// Code generated by protoc-gen-go. DO NOT EDIT.
// versions:
// protoc-gen-go v1.25.0
// protoc v3.13.0
// source: v1/beat/xyz/test.proto

package xyz

import (
proto "github.com/golang/protobuf/proto"
timestamp "github.com/golang/protobuf/ptypes/timestamp"
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
reflect "reflect"
sync "sync"
)

```

-- 
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 golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/73d8e8e9-8bcc-45b7-a121-efd765cc8b5bn%40googlegroups.com.


[go-nuts] Re: I need help writing an article about the Go implementation of hash tables

2020-10-19 Thread Marwan abdel moneim
Thanks very much, I didn't know about that talk before.
Will watch it and dive into the code, and see how far I can I understand it.

On Monday, October 19, 2020 at 3:32:38 AM UTC+2 peterGo wrote:

> GopherCon 2016: Keith Randall - Inside the Map Implementation
> https://www.youtube.com/watch?v=Tl7mi9QmLns
>
> Peter
>
>
> On Sunday, October 18, 2020 at 9:10:45 PM UTC-4, Marwan abdel moneim wrote:
>>
>> Hi,
>>
>> I have some free time, so I thought about writing an article about maps 
>> in Go, and how it is implemented. It would be a good dive for me and for 
>> other people.
>>
>> I came across this file 
>>  in the 
>> source code. But while I still remember what I studied about hash tables, I 
>> find it very complex.
>>
>> So how should I approach this task? Should I read something before 
>> reading the code?
>> How does a new developer on the Go team get to understand a part like 
>> that? 
>>
>> Thanks
>
>

-- 
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 golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/462bb116-1036-441e-b19e-94477098144bn%40googlegroups.com.


Re: [go-nuts] Option -Wl,--whole-archive seems not work

2020-10-19 Thread thierry thierry
Thanks. It works perfectly !


> On 18 Oct 2020, at 00:55, Ian Lance Taylor  wrote:
> 
> On Sat, Oct 17, 2020 at 12:25 PM Thierry Fournier
>  wrote:
>> 
>> I need to build go with an archive file which requires to be linked with the 
>> option "-Wl,--whole-archive" on linux or "-Wl,-all_load" on macos.
>> 
>> My go file contains this code:
>> 
>> /*
>> 
>> #cgo darwin LDFLAGS: -L.. -Wl,-all_load -lmy_lib
>> #cgo linux LDFLAGS: -L.. -Wl,--whole-archive -lmy_lib
>> 
>> */
>> import "C"
>> 
>> When I try to compile on Linux or Mac, this doesn't work. I read these 
>> errors:
>> 
>> Mac:
>> 
>> go build _/Users/thierryfournier/git/my-lib/my_lib: invalid flag in #cgo 
>> LDFLAGS: -Wl,-all_load
>> 
>> Linux:
>> 
>> go build _/home/thierry/my_lib/my_lib: invalid flag in #cgo LDFLAGS: 
>> -Wl,--whole-archive
>> 
>> I test the local link on both OS, and the option exists and works for c.
>> 
>> So, i don’t found any way to embed the whole library.
>> 
>> I don’t find a way to understand how the linker is called
>> I don’t find documentation about supported flag.
>> 
>> If anyone has a solution or a clue, it will be welcome
> 
> Add these flags to the CGO_LDFLAGS_ALLOW environment variable.
> 
> You may want to file an issue to get them added to the list of permitted 
> flags.
> 
> Ian

-- 
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 golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/5F66338B-50B3-47B3-A2EC-0A537F04EB5C%40gmail.com.


Re: [go-nuts] schedule a job executing in future

2020-10-19 Thread Jesper Louis Andersen
On Mon, Oct 19, 2020 at 9:51 AM Zhihong GUO  wrote:

>
> I am implementing a reminder system. The purpose is to provide API to
> client App to add a meeting, and before X minutes the meeting is to open,
> the reminder system can send notif to user by SMS or email. Here I need a
> function like: when a meeting is created, check the open time of the
> meeting, and schedule a job of sending email or sms to be executed just
> before the X minutes the meeting is open. I checked the goworker but it
> seems there is no way to enqueue a "delayed" job, any suggestions about the
> implementation?
>
>
Not knowing your design criteria, I'm just going to make some assumptions
along the way:

I'd use a database, probably postgresql. It should serve you up to at least
something like 100k concurrent meetings managed at any point in time. It'll
break apart at an even larger scale, but chances are you can rewrite with
new knowledge if that ever happens. You simply have a table tracking the
interval of each meeting and you can use this information for a lot of
things, including guarding for meeting conflicts and so on. On the Go side,
you have a job ticker (time.NewTicker(time.Minute)) and once it fires, you
look in the database if any meeting is about to start. Postgresql generally
handles time/date information well enough that you can use its internal
management to quickly query the eligible meetings. You can then decide if
you want to throw them on a channel internally and have another part of the
system responsible for sending out the emails, or if you want to do it in
the job ticker loop. I'd probably go with the former because you can have a
channel for each transport method you have (SMS, Email, Cloud Messaging[1],
etc)

In turn, the Go part of the system simply reacts to events on channels and
carries out the work. The scheduling parts are handled by the database. I
think this is a nice split of responsibility in the system, since it will
simplify both parts: the database doesn't know about transports and their
design, and the Go system doesn't have to worry about long-term persistence
of meetings.

Rationale:

* Databases can survive a system reboot or an application restart. You
probably want your meetings persistent. And you want your meetings to be
stored in a way such that you don't accidentally lose them.
* It is a rather simple poll-solution which is fast provided you have the
right indexes created on the database side.
* You can use a partial index, created over meetings for which you have yet
to send out notifications. This severely cuts the index size down.
* One-shot notifications are probably ok for a 10 minute window. If they
fail to arrive, they are not important in less than 10 minutes.
* The relational model is quite strong if you don't know where you are
going in the long run as it tends to ensure good bounds on most queries. As
you learn more about your problem, you can look into switching once your
database reaches a pain threshold (Which is a couple of terabytes for
Postgres, at the very least).

Alternative:

Use a database, but Go (Hah!) with a more cloud-DBesque solution. This
could open up for almost infinite scaling, but often has a linear cost with
the size of your database and your query rate.

[1] Consider Google's FCM solution or something similar for this route.
They demux the handling of different device types and transports for you,
as well as handle token refreshing, canonical token updates and so on for
you. It makes life much easier for everyone if you don't have to struggle
with the transport-specific APIs.

-- 
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 golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CAGrdgiUp6kj01iZfju1Mr0TNV31tkYXq%2BVLXT32Oqs_dtjS6kQ%40mail.gmail.com.


[go-nuts] schedule a job executing in future

2020-10-19 Thread Zhihong GUO
Hello all,

I am implementing a reminder system. The purpose is to provide API to
client App to add a meeting, and before X minutes the meeting is to open,
the reminder system can send notif to user by SMS or email. Here I need a
function like: when a meeting is created, check the open time of the
meeting, and schedule a job of sending email or sms to be executed just
before the X minutes the meeting is open. I checked the goworker but it
seems there is no way to enqueue a "delayed" job, any suggestions about the
implementation?

Thanks,

James

-- 
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 golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CAMhUYgyZ0c1k6DwjGwm1B1cFzFCXrH72TZ5uca_0rz%3Dmy47X5w%40mail.gmail.com.