Re: [go-nuts] Re: [ANN] Gomail v2: sending emails faster

2023-02-28 Thread Tushar Desai
Hi,

I set a timeout of 20 sec for the Dialer, but the DialAndSend continued 
beyond the timeout and sent email after 27sec.

code:
dialer = gomail.NewDialer("smtp.mailtrap.io", 587, u, p)
dialer.Timeout = 20*time.Second

start := time.Now()
if err = dialer.DialAndSend(m); err != nil {
err = fmt.Errorf("sendEmail: sending email to %s; %s", u.email, err)
return
}
elapsed := time.Since(start)
lgr.Trace().Msgf("EML %11.6fms", float64(elapsed)/float64(time.Millisecond))


Log message:
2/28 06:41:00.325 TRC EML 27604.141065ms remote=172.19.0.1
On Friday, August 25, 2017 at 9:47:12 AM UTC+5:30 Antonio Sun wrote:

> You should break that 40s up and see how long is spent on dial, and how 
> long is spent on send. 
>
> On Thu, Aug 24, 2017 at 9:41 PM,  wrote:
>
>> Thank you very much for your reply. However, in my code, it spent 40s to 
>> send email. 
>>
>> Here is the code:
>>
>> now := time.Now()
>> msg := gomail.NewMessage()
>> //the element of msg is abridged
>> dial := gomail.Dialer{Host: "127.0.0.1", Port: 25}
>> dial.TLSConfig = &tls.Config{InsecureSkipVerify: true}
>> if err := dial.DialAndSend(msg); err != nil {
>> log.Fatal("failed to send email", err)
>> } else {
>> timeSpent := fmt.Sprintf("%.3f s", time.Since(now).Seconds())
>> fmt.Println("time to spend in sending email", timeSpent )
>> }
>>
>> 在 2017年8月25日星期五 UTC+8上午1:53:48,Tamás Gulácsi写道:
>>
>>> It uses a constant 10s timeout for dial. What should time out?
>>
>> -- 
>> You received this message because you are subscribed to a topic in the 
>> Google Groups "golang-nuts" group.
>> To unsubscribe from this topic, visit 
>> https://groups.google.com/d/topic/golang-nuts/jMxZHzvvEVg/unsubscribe.
>> To unsubscribe from this group and all its topics, send an email to 
>> golang-nuts+unsubscr...@googlegroups.com.
>>
>
>> For more options, visit https://groups.google.com/d/optout.
>>
>

-- 
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/80c3ebbb-ee60-4e6f-9a29-7456bb8d94ban%40googlegroups.com.


[go-nuts] Issue implementing interface method that returns another interface

2023-02-28 Thread Rick Schubert
I am having a question about how to implement interfaces correctly in Go 
when it comes to third-party packages that use chained methods. I have 
compiled an example project below for you so that you can understand the 
problem.


package main

import (
myAPI "github.com/hashicorp/vault/api"
)

var myClient *myAPI.Client

type MyProvider interface {
GetClient() MyAPIClient
}

type MyAPIClient interface {
// I want to do this but it does not work
Logical() MyAPILogical
// This works though
// Logical() *myAPI.Logical
}

type MyAPILogical interface {
Write(path string, data map[string]interface{}) (*myAPI.Secret, error)
}

type Provider struct {}

func PublicFunctionIWantToTest(provider MyProvider) {
client := provider.GetClient()
// We normally do something here with the 'client' variable, but important
// is that we forward it later on
privateFunctionThatIsUsedInTheTest(client)
}

func privateFunctionThatIsUsedInTheTest(client MyAPIClient) (*myAPI.Secret, 
error) {
return client.Logical().Write(
"/here/goes/some/path",
map[string]interface{}{
"key": "value",
},
)
}

func NewProvider() MyProvider {
return Provider{}
}

func (p Provider) GetClient() MyAPIClient {
return myClient
}

// Empty function just so that this example can be built
func main() {}


As you can see, the package has a chained method Logical().Write() . Since 
I want to create tests for PublicFunctionIWantToTest, I want to pass down 
all the functionality as interface so that I can use 
https://vektra.github.io/mockery/ to create mocks for it.

Unfortunately, I am hitting an issue with my MyAPIClient and the 
MyAPILogical interface. Since I can see in the package's documentation 
(https://pkg.go.dev/github.com/hashicorp/vault/api@v1.8.1#Logical.Write) 
that the Logical() method returns a Logical instance, I want to make it so 
that interface method returns the other interface MyAPILogical (line 15). 
This does not work though, there is an error on line 47 in the GetClient() 
method saying that I would not implement the interface correctly. How could 
I do that?

cannot use myClient (variable of type *api.Client) as MyAPIClient value in 
return statement: *api.Client does not implement MyAPIClient (wrong type 
for method Logical)
have Logical() *api.Logical
want Logical() MyAPILogicalcompilerInvalidIfaceAssign

Thank you kindly

-- 
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/1bf2aef5-14af-4565-8f4c-538a1edeb380n%40googlegroups.com.


Re: [go-nuts] Issue implementing interface method that returns another interface

2023-02-28 Thread 'Axel Wagner' via golang-nuts
You are running into this: https://go.dev/doc/faq#covariant_types

> How could I do that?

You probably have to write a wrapper. Or change the concrete type to return
an interface. Or test using the concrete type, instead of using mocks.

On Tue, Feb 28, 2023 at 6:08 PM Rick Schubert 
wrote:

> I am having a question about how to implement interfaces correctly in Go
> when it comes to third-party packages that use chained methods. I have
> compiled an example project below for you so that you can understand the
> problem.
>
>
> package main
>
> import (
> myAPI "github.com/hashicorp/vault/api"
> )
>
> var myClient *myAPI.Client
>
> type MyProvider interface {
> GetClient() MyAPIClient
> }
>
> type MyAPIClient interface {
> // I want to do this but it does not work
> Logical() MyAPILogical
> // This works though
> // Logical() *myAPI.Logical
> }
>
> type MyAPILogical interface {
> Write(path string, data map[string]interface{}) (*myAPI.Secret, error)
> }
>
> type Provider struct {}
>
> func PublicFunctionIWantToTest(provider MyProvider) {
> client := provider.GetClient()
> // We normally do something here with the 'client' variable, but important
> // is that we forward it later on
> privateFunctionThatIsUsedInTheTest(client)
> }
>
> func privateFunctionThatIsUsedInTheTest(client MyAPIClient)
> (*myAPI.Secret, error) {
> return client.Logical().Write(
> "/here/goes/some/path",
> map[string]interface{}{
> "key": "value",
> },
> )
> }
>
> func NewProvider() MyProvider {
> return Provider{}
> }
>
> func (p Provider) GetClient() MyAPIClient {
> return myClient
> }
>
> // Empty function just so that this example can be built
> func main() {}
>
>
> As you can see, the package has a chained method Logical().Write() .
> Since I want to create tests for PublicFunctionIWantToTest, I want to
> pass down all the functionality as interface so that I can use
> https://vektra.github.io/mockery/ to create mocks for it.
>
> Unfortunately, I am hitting an issue with my MyAPIClient and the
> MyAPILogical interface. Since I can see in the package's documentation (
> https://pkg.go.dev/github.com/hashicorp/vault/api@v1.8.1#Logical.Write)
> that the Logical() method returns a Logical instance, I want to make it
> so that interface method returns the other interface MyAPILogical (line
> 15). This does not work though, there is an error on line 47 in the
> GetClient() method saying that I would not implement the interface
> correctly. How could I do that?
>
> cannot use myClient (variable of type *api.Client) as MyAPIClient value in
> return statement: *api.Client does not implement MyAPIClient (wrong type
> for method Logical)
> have Logical() *api.Logical
> want Logical() MyAPILogicalcompilerInvalidIfaceAssign
>
> Thank you kindly
>
> --
> 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/1bf2aef5-14af-4565-8f4c-538a1edeb380n%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/CAEkBMfGwN3GkWvMhBUf0MeNpBtR%2B%2B6zZHxYMF3WKxccdasQbsg%40mail.gmail.com.


[go-nuts] Re: Building Go 1.21 for openbsd/386

2023-02-28 Thread 'drc...@google.com' via golang-nuts
Try also GOMAXPROCS=1 ?  At some point not too long ago we made that dial 
down the concurrency in the compiler (before, it would do concurrent 
builds/compiles anyway) and that should reduce the maximum footprint.
On Wednesday, February 22, 2023 at 1:42:56 PM UTC-5 Jan Mercl wrote:

> The subject target is not distributed by the Go team. Attempting to build 
> if from sources in a qemu 4GB VM [OpenBSD 7.2 (GENERIC.MP) #404: Tue Sep 
> 27 12:54:46 MDT 2022] via
>
> $ GOROOT_BOOTSTRAP=~/go1.19 nohup ./make.bash
>
>   produces
>
> Building Go toolchain1 using /home/jnml/go1.19.
> Building Go bootstrap cmd/go (go_bootstrap) using Go toolchain1.
> Building Go toolchain2 using go_bootstrap and Go toolchain1.
> # cmd/compile/internal/ssa
> fatal error: runtime: out of memory
>
> runtime stack:
> runtime.throw({0x87b8037, 0x16})
> /home/jnml/goroot/src/runtime/panic.go:1047 +0x4d fp=0xcf7c860c 
> sp=0xcf7c85f8 pc=0x80832fd
> runtime.sysMapOS(0x89c0, 0x40)
> /home/jnml/goroot/src/runtime/mem_bsd.go:71 +0x144 fp=0xcf7c8638 
> sp=0xcf7c860c pc=0x805d764
> runtime.sysMap(0x89c0, 0x40, 0x8d4bc10)
> /home/jnml/goroot/src/runtime/mem.go:142 +0x3f fp=0xcf7c8648 
> sp=0xcf7c8638 pc=0x805d59f
> runtime.(*mheap).grow(0x8d3e3e0, 0x9)
> /home/jnml/goroot/src/runtime/mheap.go:1459 +0x2b1 fp=0xcf7c869c 
> sp=0xcf7c8648 pc=0x8073d51
> runtime.(*mheap).allocSpan(0x8d3e3e0, 0x9, 0x0, 0x78)
> /home/jnml/goroot/src/runtime/mheap.go:1191 +0x2f2 fp=0xcf7c872c 
> sp=0xcf7c869c pc=0x8073382
> runtime.(*mheap).alloc.func1()
> /home/jnml/goroot/src/runtime/mheap.go:910 +0x7c fp=0xcf7c8750 
> sp=0xcf7c872c pc=0x8072cfc
> runtime.systemstack()
> /home/jnml/goroot/src/runtime/asm_386.s:370 +0x35 fp=0xcf7c8754 
> sp=0xcf7c8750 pc=0x80b2305
>
> goroutine 4282 [running]:
> ...
>
> Has anyone successfully built this target from sources and can share how 
> to build Go 1.21 for openbsd/386?
>
> Thanks in advance.
>
> -j
>
>

-- 
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/f580ec4c-426b-412e-a161-40be92e3a44en%40googlegroups.com.