[go-nuts] Why doesn't Go include a contains method for things like slices?

2019-11-05 Thread toddsurfs via golang-nuts
Sorry if this question reveals my newness to Go. I tried searching the 
mailing list but I couldn't find anything in a quick search. It seems like 
many languages include the ability to check if an array, or slice contain a 
particular value. I understand that you could do this easily with a for 
loop or alternatively use a map instead. However, is there a reason why Go 
doesn't just have slice.Contains(interface{}) or maybe a builtin 
contains(mySlice, interface{}) ?

I assume one reason might be because slices could potentially be really 
large? Or maybe the community feels that a simple for loop is so easy that 
it is not necessary? I would love to understand this more.

Thank You!
-Todd

-- 
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/7d4c52e3-8c0f-4ba6-ae24-67ddb4a07ede%40googlegroups.com.


Re: [go-nuts] Why doesn't Go include a contains method for things like slices?

2019-11-05 Thread Robert Engels
Is it though?You would have the same problem if you thought the size of mySlice was always small, and it wasn't - range could be quite expensive (or not) - and if that was not valid workable you should be using something other than a slice.You need understanding of the types and cost of operations in any language, and the naming (or something else) should make the types easily recognizable (and understandable).-Original Message-
From: Tyler Compton 
Sent: Nov 5, 2019 3:57 PM
To: toddsu...@icloud.com
Cc: golang-nuts 
Subject: Re: [go-nuts] Why doesn't Go include a contains method for things like slices?

Ian's answer addresses your question about the absence of a slice.Contains method, but there have been discussions in the past about adding such a feature to the language itself as well. You brought up the idea of a builtin "contains" function, and I've seen others suggest adding something like Python's "in" operator as well. To most of these proposals, the answer has been "no" because of concerns about hiding a potentially very expensive operation behind a builtin or operator. There's no doubt that:return myObj in mySlice... is easier to miss than:for _, obj := range mySlice {    if obj == myObj {        return true    }}return falseOn Tue, Nov 5, 2019 at 12:30 PM toddsurfs via golang-nuts  wrote:Sorry if this question reveals my newness to Go. I tried searching the mailing list but I couldn't find anything in a quick search. It seems like many languages include the ability to check if an array, or slice contain a particular value. I understand that you could do this easily with a for loop or alternatively use a map instead. However, is there a reason why Go doesn't just have slice.Contains(interface{}) or maybe a builtin contains(mySlice, interface{}) ?I assume one reason might be because slices could potentially be really large? Or maybe the community feels that a simple for loop is so easy that it is not necessary? I would love to understand this more.Thank You!-Todd



-- 
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/7d4c52e3-8c0f-4ba6-ae24-67ddb4a07ede%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/CAA%3DXfu33vuhzU1krGJKUZNaj6fNOhYQQY4%2BBfNtsdq0o7Q116w%40mail.gmail.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/1726366586.12454.1572993861364%40wamui-abby.atl.sa.earthlink.net.


[go-nuts] Auto-renew letsencrypt cert with standard library code

2019-11-05 Thread Sean Liao
1. Check certificate expiry (stdlib)
2. Implement ACME client to request certificate
3. Respond to a challenge (the http one is easy)
4. Restart server with new certificate

-- 
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/fcc39ac7-dfc2-4fab-82bb-d83f37d115d1%40googlegroups.com.


Re: [go-nuts] Why doesn't Go include a contains method for things like slices?

2019-11-05 Thread Robert Engels
I think that’s splitting hairs a bit. Even if you see the loop you don’t know 
the cost unless you know the size of a slice. For instance, a lookup in a small 
slice is actually cheaper than a small map - in memory and speed. So you need 
to know more than “it’s a slice” to make a judgement. 

> On Nov 5, 2019, at 5:58 PM, Tyler Compton  wrote:
> 
> 
> I agree with you that an original writer of the code should be expected to 
> know that a theoretical "contains" or "in" expression has O(n) properties. 
> However, I've always thought of this from the perspective of someone looking 
> at the code later and trying to identify performance issues. It's easy to 
> identify a potentially very costly iteration through a slice if it's more 
> verbose and always expressed the same way.
> 
>> On Tue, Nov 5, 2019 at 2:44 PM Robert Engels  wrote:
>> Is it though?
>> 
>> You would have the same problem if you thought the size of mySlice was 
>> always small, and it wasn't - range could be quite expensive (or not) - and 
>> if that was not valid workable you should be using something other than a 
>> slice.
>> 
>> You need understanding of the types and cost of operations in any language, 
>> and the naming (or something else) should make the types easily recognizable 
>> (and understandable).
>> 
>> 
>> -Original Message- 
>> From: Tyler Compton 
>> Sent: Nov 5, 2019 3:57 PM 
>> To: toddsu...@icloud.com 
>> Cc: golang-nuts 
>> Subject: Re: [go-nuts] Why doesn't Go include a contains method for things 
>> like slices? 
>> 
>> Ian's answer addresses your question about the absence of a slice.Contains 
>> method, but there have been discussions in the past about adding such a 
>> feature to the language itself as well. You brought up the idea of a builtin 
>> "contains" function, and I've seen others suggest adding something like 
>> Python's "in" operator as well. To most of these proposals, the answer has 
>> been "no" because of concerns about hiding a potentially very expensive 
>> operation behind a builtin or operator. There's no doubt that:
>> 
>> return myObj in mySlice
>> 
>> ... is easier to miss than:
>> 
>> for _, obj := range mySlice {
>> if obj == myObj {
>> return true
>> }
>> }
>> return false
>> 
>>> On Tue, Nov 5, 2019 at 12:30 PM toddsurfs via golang-nuts 
>>>  wrote:
>>> Sorry if this question reveals my newness to Go. I tried searching the 
>>> mailing list but I couldn't find anything in a quick search. It seems like 
>>> many languages include the ability to check if an array, or slice contain a 
>>> particular value. I understand that you could do this easily with a for 
>>> loop or alternatively use a map instead. However, is there a reason why Go 
>>> doesn't just have slice.Contains(interface{}) or maybe a builtin 
>>> contains(mySlice, interface{}) ?
>>> 
>>> I assume one reason might be because slices could potentially be really 
>>> large? Or maybe the community feels that a simple for loop is so easy that 
>>> it is not necessary? I would love to understand this more.
>>> 
>>> Thank You!
>>> -Todd
>>> -- 
>>> 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/7d4c52e3-8c0f-4ba6-ae24-67ddb4a07ede%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/CAA%3DXfu33vuhzU1krGJKUZNaj6fNOhYQQY4%2BBfNtsdq0o7Q116w%40mail.gmail.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/6914AEFA-3064-45EB-ABD3-D609644B2154%40ix.netcom.com.


Re: [go-nuts] Why doesn't Go include a contains method for things like slices?

2019-11-05 Thread Tyler Compton
I agree with you that an original writer of the code should be expected to
know that a theoretical "contains" or "in" expression has O(n) properties.
However, I've always thought of this from the perspective of someone
looking at the code later and trying to identify performance issues. It's
easy to identify a potentially very costly iteration through a slice if
it's more verbose and always expressed the same way.

On Tue, Nov 5, 2019 at 2:44 PM Robert Engels  wrote:

> Is it though?
>
> You would have the same problem if you thought the size of mySlice was
> always small, and it wasn't - range could be quite expensive (or not) - and
> if that was not valid workable you should be using something other than a
> slice.
>
> You need understanding of the types and cost of operations in any
> language, and the naming (or something else) should make the types easily
> recognizable (and understandable).
>
>
> -Original Message-
> From: Tyler Compton
> Sent: Nov 5, 2019 3:57 PM
> To: toddsu...@icloud.com
> Cc: golang-nuts
> Subject: Re: [go-nuts] Why doesn't Go include a contains method for things
> like slices?
>
> Ian's answer addresses your question about the absence of a slice.Contains
> method, but there have been discussions in the past about adding such a
> feature to the language itself as well. You brought up the idea of a
> builtin "contains" function, and I've seen others suggest adding something
> like Python's "in" operator as well. To most of these proposals, the answer
> has been "no" because of concerns about hiding a potentially very expensive
> operation behind a builtin or operator. There's no doubt that:
>
> return myObj in mySlice
>
> ... is easier to miss than:
>
> for _, obj := range mySlice {
> if obj == myObj {
> return true
> }
> }
> return false
>
> On Tue, Nov 5, 2019 at 12:30 PM toddsurfs via golang-nuts <
> golang-nuts@googlegroups.com> wrote:
>
>> Sorry if this question reveals my newness to Go. I tried searching the
>> mailing list but I couldn't find anything in a quick search. It seems like
>> many languages include the ability to check if an array, or slice contain a
>> particular value. I understand that you could do this easily with a for
>> loop or alternatively use a map instead. However, is there a reason why Go
>> doesn't just have slice.Contains(interface{}) or maybe a builtin
>> contains(mySlice, interface{}) ?
>>
>> I assume one reason might be because slices could potentially be really
>> large? Or maybe the community feels that a simple for loop is so easy that
>> it is not necessary? I would love to understand this more.
>>
>> Thank You!
>> -Todd
>>
>> --
>> 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/7d4c52e3-8c0f-4ba6-ae24-67ddb4a07ede%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/CAA%3DXfu33vuhzU1krGJKUZNaj6fNOhYQQY4%2BBfNtsdq0o7Q116w%40mail.gmail.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/CAA%3DXfu1icLW8yRRX6%2BW6XVmX8k6SpkUSKNSPnejtEMdgyidu4Q%40mail.gmail.com.


Re: [go-nuts] Why doesn't Go include a contains method for things like slices?

2019-11-05 Thread Tyler Compton
I should mention that I don't 100% buy this argument and I would still like
to see a "slices.Contains" function in the future if/when generics are
added. I'm trying (perhaps poorly) to explain what I've seen as the most
common argument against adding such a feature.

On Tue, Nov 5, 2019 at 3:58 PM Tyler Compton  wrote:

> I agree with you that an original writer of the code should be expected to
> know that a theoretical "contains" or "in" expression has O(n) properties.
> However, I've always thought of this from the perspective of someone
> looking at the code later and trying to identify performance issues. It's
> easy to identify a potentially very costly iteration through a slice if
> it's more verbose and always expressed the same way.
>
> On Tue, Nov 5, 2019 at 2:44 PM Robert Engels 
> wrote:
>
>> Is it though?
>>
>> You would have the same problem if you thought the size of mySlice was
>> always small, and it wasn't - range could be quite expensive (or not) - and
>> if that was not valid workable you should be using something other than a
>> slice.
>>
>> You need understanding of the types and cost of operations in any
>> language, and the naming (or something else) should make the types easily
>> recognizable (and understandable).
>>
>>
>> -Original Message-
>> From: Tyler Compton
>> Sent: Nov 5, 2019 3:57 PM
>> To: toddsu...@icloud.com
>> Cc: golang-nuts
>> Subject: Re: [go-nuts] Why doesn't Go include a contains method for
>> things like slices?
>>
>> Ian's answer addresses your question about the absence of a
>> slice.Contains method, but there have been discussions in the past about
>> adding such a feature to the language itself as well. You brought up the
>> idea of a builtin "contains" function, and I've seen others suggest adding
>> something like Python's "in" operator as well. To most of these proposals,
>> the answer has been "no" because of concerns about hiding a potentially
>> very expensive operation behind a builtin or operator. There's no doubt
>> that:
>>
>> return myObj in mySlice
>>
>> ... is easier to miss than:
>>
>> for _, obj := range mySlice {
>> if obj == myObj {
>> return true
>> }
>> }
>> return false
>>
>> On Tue, Nov 5, 2019 at 12:30 PM toddsurfs via golang-nuts <
>> golang-nuts@googlegroups.com> wrote:
>>
>>> Sorry if this question reveals my newness to Go. I tried searching the
>>> mailing list but I couldn't find anything in a quick search. It seems like
>>> many languages include the ability to check if an array, or slice contain a
>>> particular value. I understand that you could do this easily with a for
>>> loop or alternatively use a map instead. However, is there a reason why Go
>>> doesn't just have slice.Contains(interface{}) or maybe a builtin
>>> contains(mySlice, interface{}) ?
>>>
>>> I assume one reason might be because slices could potentially be really
>>> large? Or maybe the community feels that a simple for loop is so easy that
>>> it is not necessary? I would love to understand this more.
>>>
>>> Thank You!
>>> -Todd
>>>
>>> --
>>> 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/7d4c52e3-8c0f-4ba6-ae24-67ddb4a07ede%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/CAA%3DXfu33vuhzU1krGJKUZNaj6fNOhYQQY4%2BBfNtsdq0o7Q116w%40mail.gmail.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/CAA%3DXfu0nutbzRuStD7bfWFXu5v0mGJcOpoXyc4ZLK7bW67vtaw%40mail.gmail.com.


[go-nuts] Auto-renew letsencrypt cert with standard library code

2019-11-05 Thread Michael Ellis

I have the code at the bottom of this message in a web server I'm 
running in a Digital Ocean Droplet.  The app is a simple ear training 
program for instrumentalists.  The URL is https://etudes.ellisandgrant.com.

It works with no problems until the letsencrypt certificate expires 
every 90 days.  ListenAndServeTLS() returns an error, the program exits and 
restarts (because I'm running under `entr - r`) and then falls into the 
default case which is plain http service.  I'd like to prevent that since 
modern browsers (for very good reasons) show scary warnings about plain 
http sites.  

I don't need absolute 100% uptime for the program.  A few minutes 
unavailability while the cert is renewed would be perfectly acceptable.  I 
just want to add a check at the restart to detect that the cert is expired 
and renew it automatically.  How can I do that with packages from the Go 
standard library?  ( I know Caddy is available but I'd prefer not to add a 
third-party dependency for what seems like a relatively simple task.)


var serveSecure bool
var certpath, certkeypath string
if hostport == ":443" {
certpath, certkeypath, err = getCertPaths()
if err != nil {
log.Printf("Can't find SSL certificates: %v", err)
hostport = ":80"
}
serveSecure = true
}
log.Printf("serving on %s\n", hostport)
switch serveSecure {
case true:
if err := http.ListenAndServeTLS(hostport, certpath, certkeypath, nil); err 
!= nil {
log.Fatalf("Could not listen on port %s : %v", hostport, err)
}
default:
if err := http.ListenAndServe(hostport, nil); err != nil {
log.Fatalf("Could not listen on port %s : %v", hostport, err)
}
}


/ getCertPaths attempts to retrieve a certficate and key for use with
// ListenAndServeTLS. It returns an error if either item cannot be found but
// does not otherwise attempt to validate them. That is left up to
// ListenAndServeTLS.
func getCertPaths() (certpath string, keypath string, err error) {
certpath = os.Getenv("IETUDE_CERT_PATH")
if certpath == "" {
err = fmt.Errorf("no environment variable IETUDE_CERT_PATH")
return
}
keypath = os.Getenv("IETUDE_CERTKEY_PATH")
if keypath == "" {
err = fmt.Errorf("no environment variable IETUDE_CERTKEY_PATH")
return
}
return
}

-- 
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/dc40264f-5314-496b-9069-81acbf94701a%40googlegroups.com.


Re: [go-nuts] Why doesn't Go include a contains method for things like slices?

2019-11-05 Thread Tyler Compton
Ian's answer addresses your question about the absence of a slice.Contains
method, but there have been discussions in the past about adding such a
feature to the language itself as well. You brought up the idea of a
builtin "contains" function, and I've seen others suggest adding something
like Python's "in" operator as well. To most of these proposals, the answer
has been "no" because of concerns about hiding a potentially very expensive
operation behind a builtin or operator. There's no doubt that:

return myObj in mySlice

... is easier to miss than:

for _, obj := range mySlice {
if obj == myObj {
return true
}
}
return false

On Tue, Nov 5, 2019 at 12:30 PM toddsurfs via golang-nuts <
golang-nuts@googlegroups.com> wrote:

> Sorry if this question reveals my newness to Go. I tried searching the
> mailing list but I couldn't find anything in a quick search. It seems like
> many languages include the ability to check if an array, or slice contain a
> particular value. I understand that you could do this easily with a for
> loop or alternatively use a map instead. However, is there a reason why Go
> doesn't just have slice.Contains(interface{}) or maybe a builtin
> contains(mySlice, interface{}) ?
>
> I assume one reason might be because slices could potentially be really
> large? Or maybe the community feels that a simple for loop is so easy that
> it is not necessary? I would love to understand this more.
>
> Thank You!
> -Todd
>
> --
> 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/7d4c52e3-8c0f-4ba6-ae24-67ddb4a07ede%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/CAA%3DXfu33vuhzU1krGJKUZNaj6fNOhYQQY4%2BBfNtsdq0o7Q116w%40mail.gmail.com.


Re: [go-nuts] Why doesn't Go include a contains method for things like slices?

2019-11-05 Thread Ian Lance Taylor
On Tue, Nov 5, 2019 at 12:30 PM toddsurfs via golang-nuts
 wrote:
>
> Sorry if this question reveals my newness to Go. I tried searching the 
> mailing list but I couldn't find anything in a quick search. It seems like 
> many languages include the ability to check if an array, or slice contain a 
> particular value. I understand that you could do this easily with a for loop 
> or alternatively use a map instead. However, is there a reason why Go doesn't 
> just have slice.Contains(interface{}) or maybe a builtin contains(mySlice, 
> interface{}) ?
>
> I assume one reason might be because slices could potentially be really 
> large? Or maybe the community feels that a simple for loop is so easy that it 
> is not necessary? I would love to understand this more.

This is basically the generics question: why can't you write a generic
function that operates on slices independently of the type of the
slice element?  In the absence of generics, the function has to be
written using an empty interface, which provides no compile-time type
checking.  So people just write the loop.

Using the design draft at
https://go.googlesource.com/proposal/+/master/design/go2draft-contracts.md
this would be written as

func Contains(type T comparable)(s []T, x T) bool {
for _, v := range s {
if v == x {
return true
}
}
return false
}

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/CAOyqgcUYKKFk-e1HqAAXkZz%2BBFYCHu67LnOYoRkFjF%3D%3D0mu4_A%40mail.gmail.com.


Re: [go-nuts] Auto-renew letsencrypt cert with standard library code

2019-11-05 Thread Kurtis Rader
FWIW, The Caddy web server is written in Go and handles this scenario. So
you might consider using it or at least looking at its source to understand
how to implement this feature.

On Tue, Nov 5, 2019 at 9:20 AM Michael Ellis 
wrote:

>
> I have the code at the bottom of this message in a web server I'm
> running in a Digital Ocean Droplet.  The app is a simple ear training
> program for instrumentalists.  The URL is https://etudes.ellisandgrant.com
> .
>
> It works with no problems until the letsencrypt certificate
> expires every 90 days.  ListenAndServeTLS() returns an error, the program
> exits and restarts (because I'm running under `entr - r`) and then falls
> into the default case which is plain http service.  I'd like to prevent
> that since modern browsers (for very good reasons) show scary warnings
> about plain http sites.
>
> I don't need absolute 100% uptime for the program.  A few minutes
> unavailability while the cert is renewed would be perfectly acceptable.  I
> just want to add a check at the restart to detect that the cert is expired
> and renew it automatically.  How can I do that with packages from the Go
> standard library?  ( I know Caddy is available but I'd prefer not to add a
> third-party dependency for what seems like a relatively simple task.)
>
> 
> var serveSecure bool
> var certpath, certkeypath string
> if hostport == ":443" {
> certpath, certkeypath, err = getCertPaths()
> if err != nil {
> log.Printf("Can't find SSL certificates: %v", err)
> hostport = ":80"
> }
> serveSecure = true
> }
> log.Printf("serving on %s\n", hostport)
> switch serveSecure {
> case true:
> if err := http.ListenAndServeTLS(hostport, certpath, certkeypath, nil);
> err != nil {
> log.Fatalf("Could not listen on port %s : %v", hostport, err)
> }
> default:
> if err := http.ListenAndServe(hostport, nil); err != nil {
> log.Fatalf("Could not listen on port %s : %v", hostport, err)
> }
> }
> 
>
> / getCertPaths attempts to retrieve a certficate and key for use with
> // ListenAndServeTLS. It returns an error if either item cannot be found
> but
> // does not otherwise attempt to validate them. That is left up to
> // ListenAndServeTLS.
> func getCertPaths() (certpath string, keypath string, err error) {
> certpath = os.Getenv("IETUDE_CERT_PATH")
> if certpath == "" {
> err = fmt.Errorf("no environment variable IETUDE_CERT_PATH")
> return
> }
> keypath = os.Getenv("IETUDE_CERTKEY_PATH")
> if keypath == "" {
> err = fmt.Errorf("no environment variable IETUDE_CERTKEY_PATH")
> return
> }
> return
> }
>
> --
> 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/dc40264f-5314-496b-9069-81acbf94701a%40googlegroups.com
> 
> .
>


-- 
Kurtis Rader
Caretaker of the exceptional canines Junior and Hank

-- 
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/CABx2%3DD9%2BG8pVF7om5DWdacu6V-VDMCrWR5e0WfJn8%2BCf-1CSCA%40mail.gmail.com.


Re: [go-nuts] Auto-renew letsencrypt cert with standard library code

2019-11-05 Thread Marko Ristin-Kaufmann
Hi,

FWIW, The Caddy web server is written in Go and handles this scenario. So
> you might consider using it or at least looking at its source to understand
> how to implement this feature.
>

We implemented an alternative in case you need more examples:
https://github.com/Parquery/revproxyry

Cheers,
Marko

>

-- 
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/CAGu4bVArrYN6A2yGfeVMn1wizhf%2Be5f8Ug5LV%3DW3Qt%2B7VYoUZQ%40mail.gmail.com.