[go-nuts] Re: programmatic way to find if application go binary is built with -cover flag ?

2024-05-13 Thread Tamás Gulácsi
runtime/debug.ReadBuildInfo is a good source of truth:
$ strings bin/godeb|grep '^build\s'

build   -buildmode=exe
build   -compiler=gc
build   
DefaultGODEBUG=httplaxcontentlength=1,httpmuxgo121=1,panicnil=1,tls10server=1,tlsrsakex=1,tlsunsafeekm=1
build   CGO_ENABLED=1
build   CGO_CFLAGS=
build   CGO_CPPFLAGS=
build   CGO_CXXFLAGS=
build   CGO_LDFLAGS=
build   GOARCH=amd64
build   GOOS=linux
build   GOAMD64=v1
build   -buildmode=exe
build   -compiler=gc
build   
DefaultGODEBUG=httplaxcontentlength=1,httpmuxgo121=1,panicnil=1,tls10server=1,tlsrsakex=1,tlsunsafeekm=1
build   CGO_ENABLED=1
build   CGO_CFLAGS=
build   CGO_CPPFLAGS=
build   CGO_CXXFLAGS=
build   CGO_LDFLAGS=
build   GOARCH=amd64
build   GOOS=linux
build   GOAMD64=v1

Akash Kumar a következőt írta (2024. május 13., hétfő, 18:42:30 UTC+2):

> I am writing an external go program that will take the path to another go 
> binary as argument, and checks if the binary was built with cover flag.
>
> `debug.ReadBuildInfo()` is meant for getting build info embedded in the 
> running binary as 
> > ReadBuildInfo returns the build information embedded in the running 
> binary 
>
> On Monday, May 13, 2024 at 6:37:46 PM UTC+5:30 Zxilly Chou wrote:
>
>> try debug.ReadBuildInfo(), then iterate the pair in the buildinfo.
>> Settings
>>
>> 在2024年5月13日星期一 UTC+8 20:56:51 写道:
>>
>>> Is there a way in go to find whether a go binary is built with -cover 
>>> flag ?
>>
>>

-- 
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/aa819a76-2c8e-4b9a-b37d-92abd3ff2877n%40googlegroups.com.


[go-nuts] Re: Executing JAR from Go

2024-04-15 Thread Tamás Gulácsi
Another possible error is not setting the CWD (cmd := 
exec.CommandComntext(); cmd.Dir = `the-dir-where-DigitalSign,jar-is`).

Tamás Gulácsi a következőt írta (2024. április 16., kedd, 6:20:50 UTC+2):

> What is the _working_ command line?
> Ain't something like ```java -cp ... -jar DigitalSign.jar org.Sign``` ?
>
> Shivli Srivastava a következőt írta (2024. április 15., hétfő, 13:04:28 
> UTC+2):
>
>> this is my code
>>
>> func runCommand(ctx context.Context) (string, error) {
>>
>> if JVMFound(context.Background()) {
>> jarPath := "/Users/shivli.srivastava/Downloads/jars/bcmail-jdk15on-159.jar:" 
>> +
>> "/Users/shivli.srivastava/Downloads/jars/bcpkix-jdk15on-155.jar:" +
>> "/Users/shivli.srivastava/Downloads/jars/bcprov-jdk15on-155.jar:" +
>> "/Users/shivli.srivastava/Downloads/jars/xml-apis-1.4.01.jar:" +
>> "/Users/shivli.srivastava/Downloads/jars/xercesImpl-2.12.2.jar:" +
>> "DigitalSign.jar"
>>
>> output, err := exec.Command("java", "-cp", jarPath, "org/Sign").
>> CombinedOutput()
>> boot.Logger(ctx).Infow("", map[string]interface{}{
>> "output": string(output),
>> })
>> //cmd.Env = os.Environ()
>>
>> if err != nil {
>> return "", err
>> }
>>
>> return string(output), nil
>> }
>> return "", cerror.InternalGatewayError.New("").Wrap(fmt.Errorf("JVM Not 
>> Found"))
>> }
>>
>> On Monday, April 15, 2024 at 4:32:24 PM UTC+5:30 Shivli Srivastava wrote:
>>
>>> I created a jar where I want to run the main function of the Sign class 
>>> . 
>>>
>>>
>>> *jar tf DigitalSign.jar*
>>> META-INF/MANIFEST.MF
>>> org/
>>> org/Sign.class
>>> META-INF/
>>> bcmail-jdk15on-1.59.jar
>>> xml-apis-1.4.01.jar
>>> xercesImpl-2.12.2.jar
>>> bcutil-jdk18on-1.77.jar
>>> bcprov-jdk18on-1.77.jar
>>> bcpkix-jdk15on-1.55.jar
>>> bcprov-jdk15on-1.59.jar
>>>
>>> When I run the command on my terminal , everything works as fine but 
>>> running it using exec.Command gives 
>>>
>>> *Error: Could not find or load main class org.SignCaused by: 
>>> java.lang.ClassNotFoundException: org.Sign . *
>>> What am I missing here ?
>>
>>

-- 
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/87085b40-153d-4e0a-983b-69ab51804377n%40googlegroups.com.


[go-nuts] Re: Executing JAR from Go

2024-04-15 Thread Tamás Gulácsi
What is the _working_ command line?
Ain't something like ```java -cp ... -jar DigitalSign.jar org.Sign``` ?

Shivli Srivastava a következőt írta (2024. április 15., hétfő, 13:04:28 
UTC+2):

> this is my code
>
> func runCommand(ctx context.Context) (string, error) {
>
> if JVMFound(context.Background()) {
> jarPath := "/Users/shivli.srivastava/Downloads/jars/bcmail-jdk15on-159.jar:" 
> +
> "/Users/shivli.srivastava/Downloads/jars/bcpkix-jdk15on-155.jar:" +
> "/Users/shivli.srivastava/Downloads/jars/bcprov-jdk15on-155.jar:" +
> "/Users/shivli.srivastava/Downloads/jars/xml-apis-1.4.01.jar:" +
> "/Users/shivli.srivastava/Downloads/jars/xercesImpl-2.12.2.jar:" +
> "DigitalSign.jar"
>
> output, err := exec.Command("java", "-cp", jarPath, "org/Sign").
> CombinedOutput()
> boot.Logger(ctx).Infow("", map[string]interface{}{
> "output": string(output),
> })
> //cmd.Env = os.Environ()
>
> if err != nil {
> return "", err
> }
>
> return string(output), nil
> }
> return "", cerror.InternalGatewayError.New("").Wrap(fmt.Errorf("JVM Not 
> Found"))
> }
>
> On Monday, April 15, 2024 at 4:32:24 PM UTC+5:30 Shivli Srivastava wrote:
>
>> I created a jar where I want to run the main function of the Sign class . 
>>
>>
>> *jar tf DigitalSign.jar*
>> META-INF/MANIFEST.MF
>> org/
>> org/Sign.class
>> META-INF/
>> bcmail-jdk15on-1.59.jar
>> xml-apis-1.4.01.jar
>> xercesImpl-2.12.2.jar
>> bcutil-jdk18on-1.77.jar
>> bcprov-jdk18on-1.77.jar
>> bcpkix-jdk15on-1.55.jar
>> bcprov-jdk15on-1.59.jar
>>
>> When I run the command on my terminal , everything works as fine but 
>> running it using exec.Command gives 
>>
>> *Error: Could not find or load main class org.SignCaused by: 
>> java.lang.ClassNotFoundException: org.Sign . *
>> What am I missing here ?
>
>

-- 
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/bfb58b2d-027b-4304-8602-43da4adaf372n%40googlegroups.com.


[go-nuts] Re: CMSSignedData in Golang

2024-04-02 Thread Tamás Gulácsi
Earlier questions bubbled up 
https://pkg.go.dev/github.com/fullsailor/pkcs7?utm_source=godoc#SignedData
(https://github.com/smallstep/pkcs7)

For the XML canonicalization, you may try 
https://pkg.go.dev/github.com/lafriks/go-xmldsig/v2#Canonicalizer



Shivli Srivastava a következőt írta (2024. április 2., kedd, 15:43:54 
UTC+2):

> I have to replicate the Java code for signing xml in Go. The java code 
> uses org.bouncycastle.cms.CMSSignedData from BouncyCastle for signing and 
> org.apache.xml.serialize.XMLSerializer for Serializing the input xml . 
>
> The signing process should be exactly same as the signature otherwise 
> would be different and I cannot afford that . Any help will be appreciated
>
>
> Regards
> Shivli
>

-- 
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/b6334304-207a-4c5d-a770-9dc5beed4f12n%40googlegroups.com.


Re: [go-nuts] io.Reader can return (n, err), both non-zero

2024-03-25 Thread Tamás Gulácsi
I don't really get it.
The current documentation says that bespite err!=nil, some data may be read 
(n!=0).
If one obeys this rule, then it will consume the data, then handle the 
error.

If we change then io.Reader's documentation (and all std lib 
implementations)...

Ok, now I may be understand: If an io.Reader implementation obeys this 
stricter rule, then it would become wrong with the new (lax) rule...
What about some documentation and an "func io.Read(io.Reader, p) (int, 
error)" wrapper function that caches the error and only returns err!=nil 
iff n!=0 ?

But this maybe just complicate things?

Diego Joss a következőt írta (2024. március 25., hétfő, 10:16:43 UTC+1):

> Hi
>
> On Thu, 21 Mar 2024 at 19:23, 'Christian Stewart' via golang-nuts <
> golan...@googlegroups.com> wrote:
>
>> When sending Read() via an RPC call or traversing locks, it is 
>> significantly faster to return EOF in the same call as returning the rest 
>> of the available data, than to call Read a second time to get the EOF.
>>
>
> Just for sake of discussion/argumentation, it's still possible for the 
> callee implementation to cache the error status which is returned in the 
> next Read call. Thus a single RPC (or lock) call is performed.
>
> -- 
> Diego Joss
>

-- 
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/8a139eee-f727-4b2a-bf54-0389848d5df1n%40googlegroups.com.


Re: [go-nuts] evaluation of range expression in for-range loop

2024-02-05 Thread Tamás Gulácsi
Yes.
If you manipulate the meaning of the index (i) or the length of the slice, 
then do it explicitly:

for i := 0; i < len(a); i++ {
  if a[i] == 0 { //delete
a[i]=a[0]
a = a[1:]
i--
  }
}

For other methods, see 
https://go.dev/wiki/SliceTricks#filtering-without-allocating

Shivansh Rustagi a következőt írta (2024. február 5., hétfő, 15:29:06 
UTC+1):

> Hi Guys, I had a question regarding:
>
> > On the other hand, if you have `for i, v := range a {` then the
> > expression *is* evaluated before the start of the loop.
>
> I have a code (https://goplay.tools/snippet/dMwD0_rEhkB) where I am 
> ranging over a slice, and updating (removing the zeroth element form the 
> same slice being ranged over) here I see that the "i" values is not being 
> re-evaluated, it just gives an increasing number even if the ranged over 
> slice has changed . Which can also be seen when I am printing the ith 
> element given to me by the range, and the receiving out of range panic
>
> On Saturday, March 19, 2022 at 2:01:27 AM UTC+5:30 Dan Kortschak wrote:
>
>> On Fri, 2022-03-18 at 16:53 +0100, 'Axel Wagner' via golang-nuts wrote: 
>> > One thing to keep in mind is that Go development was incremental and 
>> > was done, from early on, by having multiple implementations. 
>> > Incremental processes often lead to different results than designing 
>> > a language from a blank slate. Ambiguities in the spec are often 
>> > discovered only when someone notices that implementations disagree 
>> > and must be resolved somehow. Sometimes that happens after Go 1 and 
>> > the resolution must happen in a way that, as much as possible, 
>> > retains stability guarantees. So, it's not unsurprising if we get 
>> > non-obvious spec clauses such as this. 
>> > 
>> > Specifically, I can well imagine that this particular case arose, 
>> > because it was discovered after the fact that one implementation 
>> > contained an optimization to not evaluate the argument to `len`, 
>> > while the other didn't and the question of side-effects only arose 
>> > when someone noticed. 
>> > 
>> > I don't really know the answer to your question. I can't think of 
>> > anything which would break. That being said, I also don't think it's 
>> > something that really needs "fixing", as it seems a pretty uncommon 
>> > concern. 
>>
>> There is some discussion on the reasons when the original narrowing of 
>> the behaviour was introduced (https://codereview.appspot.com/050). 
>>
>> It's actually quite an interesting spec change from a language history 
>> perspective, more because of the chan discussion than this particular 
>> issue. 
>>
>>
>>

-- 
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/237f0947-82e3-4467-834c-3c5fbfbb698dn%40googlegroups.com.


[go-nuts] Re: Scrapping with Colly - Pulling Elements one at a time

2024-01-28 Thread Tamás Gulácsi
var data MemberDetails

detailCollector.OnHTML("div.block-container div.block-body:first-of-type", 
func(h *colly.HTMLElement) { 
selection := h.DOM 
key := selection.Find("dl > dt").Text() 
val := selection.Find("dl > dd").Text() 
switch key {
case "Full name": data.FullName = val
case "Rank": data.Rank = val
case "Primary position": data.PrimaryPosition = val
}
})

fmt.Printf("data: %+v\n", data)

Enrique a következőt írta (2024. január 29., hétfő, 3:21:32 UTC+1):

> Hello, I am new to golang, and am working on a small web scrapper project, 
> where i crawl through a website for a guild that i'm associated with.
>
> Ideally I would like to pull the data from each 'dl' (html below) and 
> insert it into the MemberDetails Struct, however all attempts to parse the 
> below html result in the following string being returned
>
> Printout dt - 0: [Full nameRankPrimary position]
>
> Do you have any advice on how I could get one element at a time?
>
>- Full Name
>- John Doe
>
> Note: Library being used github.com/gocolly/colly
>  
> Information   Full name John Doe  <
> dl class="pairs pairs--columns rosters-rows"> Rank Rank #1 dd>   Primary 
> position General Staff  >  type 
> MemberDetails struct { FullName string Rank string PrimaryPosition string 
> } // ... detailCollector.OnHTML("div.block-container 
> div.block-body:first-of-type", func(h *colly.HTMLElement) { selection := 
> h.DOM val := selection.Find("dl > dt").Text() fmt.Printf("Printout dt - 
> 0: %s \n", val) }) 

-- 
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/fd2dc57d-2b40-4d7b-a753-252a1cbc135bn%40googlegroups.com.


[go-nuts] Re: Passing 2d arrays from Go to C using runtime.Pinner

2024-01-26 Thread Tamás Gulácsi
To convert a Go slice to C array is easy with unsafe.Slice.

The problem is that the multi-dimensional C array is an array of pointers 
(*(*float64))
which cannot travel between the C/Go barrier.

In your example, you flatten your slice, and recreate the pointers in that 
one big slice.
You could go on with that example, but from the Go side:

1. have a "flat" []float64 wihich is N*M
2. have the [][]float64 as subslices of that one big flattened []float64: 
flat[i*M:i*(M+1)]
3. send that flat slice to the C side with unsafe.Slice
4. have the C side implement the same subslicing: create a []*float64 array 
and have each point to the corredt [i*M].
5. profit


Denis a következőt írta (2024. január 26., péntek, 1:18:59 UTC+1):

> I am trying to pass 2d array from Go to some C function void foo(in 
> **float, out *double). Since I want to have wrapper for this C function, 
> I'd like that Go function has definition like func 
> FooWrapper([][]float32) []float64. The easiest but not efficient 
> implementation is allocating all memory through C that listed below:
>
> func FooWrapper(values [][]float32) []float64 {
> totalObj := len(values)
> totalParams := len(values[0])
> results := make([]float64, totalObj)
>
> ptrArrLength := uintptr(totalObj) * cPointerSize
> paramArrLength := uintptr(totalParams) * cFloatSize
>
> ptr := C.malloc(C.size_t(ptrArrLength + 
> paramArrLength*uintptr(totalObj)))
> defer C.free(ptr)
>
> ptrSlice := unsafe.Slice((**C.float)(ptr), totalObj)
> for i, obj := range values {
> paramArrPtr := (*C.float)(unsafe.Add(ptr, 
> ptrArrLength+uintptr(i)*paramArrLength))
> ptrSlice[i] = paramArrPtr
>
> paramSlice := unsafe.Slice(paramArrPtr, totalParams)
> for j, param := range obj {
> paramSlice[j] = (C.float)(param)
> }
> }
>
> C.foo((**C.float)(ptr), (*C.double)([0]))
>
> return results
> }
>
> Is that safe implementation? Can I pass pointer of result data? As far as 
> I know, this pointer will be pinned because it passed to C function.
>
> But I want to allocate less memory just reusing Go memory, I've learned 
> about runtime.Pinner that make pointer pinned until runtime.Pinner.Unpin() 
> invocation. 
> I tried to write another implementation using pinner:
>
> func FooWrapper(values [][]float32) []float64 {
> length := len(values)
> results := make([]float64, length)
>
> pinner := runtime.Pinner{}
> defer pinner.Unpin()
>
> arr := (**C.float)(C.malloc(C.size_t(uintptr(length) * cPointerSize)))
> defer C.free(unsafe.Pointer(arr))
> slice := unsafe.Slice(arr, length)
> for i, v := range values {
> pinner.Pin([0])
> slice[i] = (*C.float)([0])
> }
>
> C.foo(arr, (*C.double)([0]))
>
> return results
> }
>
> But, unfortunately, this code doesn't work
>
> runtime: pointer 0xc016ecbfc0 to unused region of span 
> span.base()=0xc016eca000 span.limit=0xc016ecbfa0 span.state=1
> fatal error: found bad pointer in Go heap (incorrect use of unsafe or cgo?)
>
> Do I use runtime.Pinner wrong (as far as I know, I can pin slice data)? Or 
> there is another error in this code. Are there some implementations for 
> passing 3d (4d and so on) array to C function except for allocatiing and 
> copying all data to C memory?
>

-- 
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/8068c8df-6290-45a2-a08f-569a062f045fn%40googlegroups.com.


[go-nuts] Re: CGO unpinned Go pointer panic

2024-01-08 Thread Tamás Gulácsi
That should work. Are you sure that those ellipses (...) does not contain 
some other pointers?

Brent Bailey a következőt írta (2024. január 8., hétfő, 3:06:35 UTC+1):

> I'm trying to pass a pointer to an external C library using Go 1.21 and 
> get the following runtime panic:
> panic: runtime error: cgo argument has Go pointer to unpinned Go pointer
>
> My first attempt was:
> var bufferSize int = 0
> C.external_library(...,(*C.size_t)(unsafe.Pointer()))
>
> I tried to pin the memory using the Pinner type in the runtime library:
> var bufferSize int = 0
> ptr := 
> var p runtime.Pinner
> p.Pin(ptr)
>
> C.external_library(...,(*C.size_t)(unsafe.Pointer(ptr)))
>
> p.Unpin()
> which resulted in the same error.
>
> I tried creating the pointer in C as follows:
> var ptr unsafe.Pointer
> ptr = C.malloc(C.size_t(4))
>
> C.external_library(...,(*C.size_t)(ptr))
>
> bufferSize := *(*int)(ptr)
> C.free(ptr)
> but the error persisted.
>
> What am I doing wrong? 
>

-- 
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/bc969a5f-e607-470c-8cfd-bee0aa35b7f7n%40googlegroups.com.


[go-nuts] Re: [RFC] Syntactic Dissonance

2024-01-06 Thread Tamás Gulácsi
Where does TestObject implement the Comparable interface, esp. the Compare 
method?
I don't see such in that rep.
The implemented TestObject.Compare method has different signature: it 
requests a TestObject, not a Comparable interface, as your spec!
This is only the first error.

The second is that a slice of objects cannot be converted to a slice of 
interface - only by manually copying:

```
diff --git a/sort_test.go b/sort_test.go
index 0874721..c89b3b3 100644
--- a/sort_test.go
+++ b/sort_test.go
@@ -13,10 +13,10 @@ type TestObject string
 
 type TestList []TestObject
 
-func (this TestObject) Compare(that TestObject) int {
+func (this TestObject) Compare(that Comparable) int {
 
  var bi, bj byte
- var x, y, z int = 0, len(this), len(that)
+ var x, y, z int = 0, len(this), len(that.(TestObject))
  var d, c int = 0, 0
 
  if y == z {
@@ -34,7 +34,7 @@ func (this TestObject) Compare(that TestObject) int {
 
  for ; x < c; x++ {
  bi = this[x]
- bj = that[x]
+ bj = (that.(TestObject))[x]
  if bi != bj {
 
  if bi < bj {
@@ -58,7 +58,11 @@ func (this TestList) Print() {
 func TestSort(t *testing.T) {
  var vector TestList = TestList{TestObject("20231219192613"), 
TestObject("20231221074246"), TestObject("20240102214104"), 
TestObject("20231222063428"), TestObject("20240104112200"), 
TestObject("20231217190339"), TestObject("20231213155157"), 
TestObject("20231219065525"), TestObject("20231231120412"), 
TestObject("20231221152849"), TestObject("20240102073948"), 
TestObject("20240101083455")}
 
- Sort(vector)
+ objs := make([]Comparable, len(vector))
+ for i := range vector {
+ objs[i] = vector[i]
+ }
+ Sort(objs)
 
  vector.Print()
 }
```
John Pritchard a következőt írta (2024. január 6., szombat, 8:53:01 UTC+1):

> Hi,
>
> Here's a case of "type dissonance" I don't understand.  Why should it be?
>
> https://github.com/syntelos/go-sort
>
>
> An interface type not passing through a static public package function 
> that employs the interface.
>
> type Comparable interface {
>
>
> Compare(Comparable) int
>
> }
>
> func Sort(array []Comparable) ([]Comparable)
>
>
> With go-1.20.12:
>
> $ go test
> # github.com/syntelos/go-sort [github.com/syntelos/go-sort.test]
> ./sort_test.go:61:7: cannot use vector (variable of type TestList) as 
> []Comparable value in argument to Sort
> FAILgithub.com/syntelos/go-sort [build failed]
>
>
> Any comments?
>
> Best,
>
> John
>
>
>

-- 
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/ba7239c1-cb52-4f86-9e56-da6ffa721fa5n%40googlegroups.com.


[go-nuts] Re: Maintaining a connection to Postgresql during database failover

2023-12-31 Thread Tamás Gulácsi
This is just from reading the docs:
https://pkg.go.dev/github.com/jackc/pgx/v5@v5.5.1/pgconn#FallbackConfig
is a member of 
https://pkg.go.dev/github.com/jackc/pgx/v5@v5.5.1/pgconn#Config
and its comment seems to match your use case.

I don;t know AWS RDS how does the failover (when is the connection closed), 
but the "table not found" error suggest you have to set the 
Config.AfterConnect parameter, too (see its comment).
Dean Schulze a következőt írta (2024. január 1., hétfő, 3:54:02 UTC+1):

> I have a web service in Gin that calls Postgresql running on AWS RDS with 
> multi-az failover.  When I reboot with failover the primary database and 
> failover starts calls to the web service hang without even getting to the 
> event handler.  Once the failover is complete calls to the web service fail 
> due to not being able to find the Postgresql table.  If I restart the web 
> service then calls to the web service succeed.
>
> I've done this with both sql/db and the github.com/jackc/pgx/v5/pgxpool 
> connection pool.  I hoped the pgxpool would be resilient enough to 
> reconnect once multi-az failover had completed, but this isn't happening.
>
> I could implement retry logic which would probably require a new 
> connection, but the calls that hang don't even get to the event handler.
>
> Is there a pattern for supporting continuing connection or reconnect to 
> Postgresql when failover happens?  Are there drivers or packages that 
> implement this?
>

-- 
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/ab1b5d87-cf31-49a6-872b-d074442ee213n%40googlegroups.com.


[go-nuts] Re: Is there a Go equivalent to Python's ctypes library?

2023-11-21 Thread Tamás Gulácsi
Which is what?
Please share with the golang-nuts list if you've found a solution!

Mark a következőt írta (2023. november 21., kedd, 11:54:11 UTC+1):

> Thank you, that looks just like what I want.
>
> On Tuesday, November 21, 2023 at 10:21:14 AM UTC Mark wrote:
>
>> I would like to be able to access a dynamic C library (and ideally C++), 
>> i.e., `.so` or `.dll` _without_ using cgo, i.e., without needing a compiler 
>> on the target platform.
>> Python provides a `ctypes` module with this facility. Is there an 
>> equivalent for Go?
>>
>

-- 
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/605afdc7-0e27-4480-8f60-41b9ccb0ee64n%40googlegroups.com.


[go-nuts] Re: Golang embed with http and middleware

2023-11-19 Thread Tamás Gulácsi
https://blog.carlmjohnson.net/post/2021/how-to-use-go-embed/ is a more 
comprehensive article on using embed.

Tamás Gulácsi a következőt írta (2023. november 20., hétfő, 6:28:44 UTC+1):

> You can convert a io/fs.FS to a http FS with http.FS.
> For an example, see https://stackoverflow.com/a/66248259
>
>
> Daryl Williams a következőt írta (2023. november 20., hétfő, 0:15:29 
> UTC+1):
>
>> I am trying to find out if the http server can work with the embed 
>> filesystem and also use middleware? And if so are there any articles 
>> describing how to do this?
>>
>> Asks in advance,
>>
>> Daryl
>>
>

-- 
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/e69a0ef1-960a-480d-b1a2-a3f8765ba741n%40googlegroups.com.


[go-nuts] Re: Golang embed with http and middleware

2023-11-19 Thread Tamás Gulácsi
You can convert a io/fs.FS to a http FS with http.FS.
For an example, see https://stackoverflow.com/a/66248259


Daryl Williams a következőt írta (2023. november 20., hétfő, 0:15:29 UTC+1):

> I am trying to find out if the http server can work with the embed 
> filesystem and also use middleware? And if so are there any articles 
> describing how to do this?
>
> Asks in advance,
>
> Daryl
>

-- 
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/ea75cbfc-651e-4ddc-b647-7311a58bff15n%40googlegroups.com.


Re: [go-nuts] Is "When in doubt, use a pointer receiver" misleading advice?

2023-11-13 Thread Tamás Gulácsi
I've always try to start with a value receiver,
change to pointer receiver (EVERYWHERE - do not mix pointer and value 
receivers!),
when the method modifies the sruct's members (or just have a sync.Mutex 
member),
or used as interface (i.e. error  - for comparison to nil)

Oliver Lowe a következőt írta (2023. november 14., kedd, 0:23:44 UTC+1):

> > I'd be curious to hear thoughts on this topic.
>
> There was a fun talk at GopherConAU just a few days ago: "What's
> The Point? A Guide To Using Pointers Without Panicking" (talk
> description at https://gophercon.com.au/) When the recordings are
> all finalised I can reply to this thread with a link.
>

-- 
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/c4bd392c-8561-4cde-89f0-677fde9ea241n%40googlegroups.com.


[go-nuts] Re: Go has stolen several hours from the twentieth century Hungary

2023-10-22 Thread Tamás Gulácsi
In tzdb/europe: 
RuleHungary 1954only-   May 23   0:00   1:00S
RuleHungary 1980only-   Apr  6   0:00   1:00S
RuleHungary 19811983-   Mar lastSun  0:00   1:00S

If I interpret it  correctly, my "bad" dates are when the clock has been 
adjusted at midnight from 0:00 to 1:00,
just like now from 2:00 to 3:00.

My problem with this is that I wanted to do the "right thing", and added 
time zone information 
from DATE values returned from Oracle DB in the godror driver.

The DB stores 1954-05-23 (00:00:00), which have not existed in 
Europe/Budapest time zone.

Maybe I have to accept this discrepancy for these handful  of dates.
Any better idea?
Tamás Gulácsi a következőt írta (2023. október 22., vasárnap, 15:16:51 
UTC+2):

> https://go.dev/play/p/qkPmfu1sCyU
>
> 1954-05-22
> 1980-04-06
> 1981-03-29
> 1982-03-28
> 1983-03-27
>
> has the first second in the day as 01:00:00
>
> The previous second is of the previous day.
>
>
> Maybe it's just TZ history, and these dates had the DST change betweem 
> 00:00:00 and 01:00:00, eliminating that hour (not the nowadays ususal set 
> to 3 at 2 o'clock).
>
> I just don't know enough about this, that's why I'm asking.
>
> Thanks in advance,
> Tamás Gulácsi
>

-- 
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/0405ad9c-72fd-4794-bb87-487a62fe8a9fn%40googlegroups.com.


[go-nuts] Go has stolen several hours from the twentieth century Hungary

2023-10-22 Thread Tamás Gulácsi
https://go.dev/play/p/qkPmfu1sCyU

1954-05-22
1980-04-06
1981-03-29
1982-03-28
1983-03-27

has the first second in the day as 01:00:00

The previous second is of the previous day.


Maybe it's just TZ history, and these dates had the DST change betweem 
00:00:00 and 01:00:00, eliminating that hour (not the nowadays ususal set 
to 3 at 2 o'clock).

I just don't know enough about this, that's why I'm asking.

Thanks in advance,
Tamás Gulácsi

-- 
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/29ce91da-cddd-416d-900a-fa295529f9fbn%40googlegroups.com.


[go-nuts] Re: Recommended way to distribute pre-compiled C-dependencies for modules using CGO ?

2023-10-14 Thread Tamás Gulácsi
Neither I see a convenient way.
BUT if you add a .go file into the directories where your precompiled 
libraries live,
then "go get" will download them too (and only those dirs that have .go 
files in it).

So your next mission is to prepare the right #cgo CFLAGS LDFLAGS 
incantations to use those libraries.

Jan a következőt írta (2023. október 14., szombat, 8:37:48 UTC+2):

> Thanks Tamás, I may not be understanding correctly, but after taking a 
> look at github.com/godror/godror, and the odpi subdirectory,
> I see it is including all the `.c` files on the fly 
> <https://github.com/godror/godror/blob/main/odpi/embed/dpi.c>.
>
> A couple of reasons immediately come to mind, that make this not a 
> generically valid option:
>
> * ODPI library is all C code (see src 
> <https://github.com/godror/godror/tree/main/odpi/src>) so it works 
> including in Go: my dependencies are C++/Rust code, for which I write a 
> small C wrapper (or for Rust just `extern "C"`). Also architecture 
> dependent compilation is different in C++/C/Rust code ...
> * The C++ libraries I'm including have sub-dependencies of themselves (one 
> of which is llvm). It uses Bazel to organize it, and to manually move all 
> the required C++ files to a directory would be years of work :) Plus would 
> require me to slave to maintain things in sync. 
> * The C++ libraries take hours to compile ... I don't want to impose this 
> to users of my libraries.
>
> I think the only way to work this out is distributing the pre-compiled 
> C++/Rust libraries, so the Go simply refer to them (and we get the fast 
> compilation times from Go). But then, how to best distribute them in an 
> automatic fashion, so that users don't need to one by one figure out how to 
> install them (and clean up them later if they are no longer using...) ?
>
> Or maybe there is another convenient way I'm not seeing ?
>
>
> On Thursday, October 12, 2023 at 6:39:34 PM UTC+2 Tamás Gulácsi wrote:
>
>> Can't you build (make go build for you) those libraries?
>> For example, see github.com/godror/godror just includes the sources of 
>> that third party library in an "odpi" subdir, and with
>> ```
>> /*
>> #cgo CFLAGS: -I./odpi/include -I./odpi/src -I./odpi/embed
>>
>> #include "dpi.c"
>>
>> */
>> import "C"
>> ```
>> it is compiled automatically.
>>
>>
>> Caveat: for "go get" to download a directory, it must include a sth.go 
>> file ("require.go" in the odpi/* subdirs).
>> But it may work that your precompiled libs in a subdir, with a mock .go 
>> file gets downloaded.
>> But how will it found by your lib/app ?
>>
>> Tamás
>>
>>
>> Jan a következőt írta (2023. október 12., csütörtök, 8:14:41 UTC+2):
>>
>>> Thanks Richard. Indeed, as you pointed out the downside is the bloating 
>>> of the git repo, but it makes sense.
>>>
>>> But does the user have to manually clone the repository and move the 
>>> `.a` file to, let's say, /usr/local/lib, or does a simple `go get` 
>>> magically does everything ?
>>>
>>>
>>> On Thursday, October 12, 2023 at 2:29:21 AM UTC+2 Richard Wilkes wrote:
>>>
>>>> It isn't a great solution, but I currently include the built library 
>>>> files and necessary headers in the git repo alongside the Go code. You can 
>>>> see an example here 
>>>> https://github.com/richardwilkes/unison/tree/main/internal/skia where 
>>>> I include the skia library I built for use in my UI framework, unison.
>>>>
>>>> The main downside of this is bloating the git repo with the binary .a 
>>>> and .dll files... but I've not found a better way to handle it. glfw, 
>>>> which 
>>>> unison also depends upon, does something very similar.
>>>>
>>>> - Rich
>>>>
>>>> On Wednesday, October 11, 2023 at 2:58:23 AM UTC-7 Jan wrote:
>>>>
>>>>> hi,
>>>>>
>>>>> I'm developing a couple of ML framework/libraries for Go that depend 
>>>>> on C/C++ code. Once C-libraries dependencies are installed, the CGO 
>>>>> integration work great.
>>>>>
>>>>> Now, for end-users that just want to use these Go libraries, having to 
>>>>> figure out how to manually build and install those C/C++/Rust 
>>>>> dependencies 
>>>>> is a hassle -- sadly each one with a different type of build system.
>>>>>
>>>>> I offer pre-built `.tgz` fi

[go-nuts] Re: Recommended way to distribute pre-compiled C-dependencies for modules using CGO ?

2023-10-12 Thread Tamás Gulácsi
Can't you build (make go build for you) those libraries?
For example, see github.com/godror/godror just includes the sources of that 
third party library in an "odpi" subdir, and with
```
/*
#cgo CFLAGS: -I./odpi/include -I./odpi/src -I./odpi/embed

#include "dpi.c"

*/
import "C"
```
it is compiled automatically.


Caveat: for "go get" to download a directory, it must include a sth.go file 
("require.go" in the odpi/* subdirs).
But it may work that your precompiled libs in a subdir, with a mock .go 
file gets downloaded.
But how will it found by your lib/app ?

Tamás


Jan a következőt írta (2023. október 12., csütörtök, 8:14:41 UTC+2):

> Thanks Richard. Indeed, as you pointed out the downside is the bloating of 
> the git repo, but it makes sense.
>
> But does the user have to manually clone the repository and move the `.a` 
> file to, let's say, /usr/local/lib, or does a simple `go get` magically 
> does everything ?
>
>
> On Thursday, October 12, 2023 at 2:29:21 AM UTC+2 Richard Wilkes wrote:
>
>> It isn't a great solution, but I currently include the built library 
>> files and necessary headers in the git repo alongside the Go code. You can 
>> see an example here 
>> https://github.com/richardwilkes/unison/tree/main/internal/skia where I 
>> include the skia library I built for use in my UI framework, unison.
>>
>> The main downside of this is bloating the git repo with the binary .a and 
>> .dll files... but I've not found a better way to handle it. glfw, which 
>> unison also depends upon, does something very similar.
>>
>> - Rich
>>
>> On Wednesday, October 11, 2023 at 2:58:23 AM UTC-7 Jan wrote:
>>
>>> hi,
>>>
>>> I'm developing a couple of ML framework/libraries for Go that depend on 
>>> C/C++ code. Once C-libraries dependencies are installed, the CGO 
>>> integration work great.
>>>
>>> Now, for end-users that just want to use these Go libraries, having to 
>>> figure out how to manually build and install those C/C++/Rust dependencies 
>>> is a hassle -- sadly each one with a different type of build system.
>>>
>>> I offer pre-built `.tgz` files (for a limited set of architectures) with 
>>> the required `.h` and `.a/.so` files along the releases, which facilitates. 
>>> But it's still a hassle to install -- and no auto-uninstall if someone is 
>>> no longer using the Go module.
>>>
>>> I was wondering if others have figured out how to handle this in a nicer 
>>> way.  Is there a recommended way to distribute prebuilt CGO dependencies ?
>>>
>>> I like how Python wheels (`.whl` files) solve the issue, by including 
>>> the pre-built libraries in a sub-directory of the python library 
>>> installation. I was hoping there would be a similar way (maybe with a 
>>> separate tool) to integrate with `go.mod`. 
>>>
>>> Any pointers, thoughts or suggestions are very appreciated.
>>>
>>> Thanks!
>>> Jan
>>>
>>> ps: While searching I saw similar questions, but none that exactly 
>>> answered this aspect of distribution. Just in case, apologies if it's a 
>>> duplicate question.
>>>
>>

-- 
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/1624fe5e-ec87-4022-91f5-d9990594c183n%40googlegroups.com.


[go-nuts] Re: Encrypting a small secret using curve25519

2023-09-20 Thread Tamás Gulácsi
https://pkg.go.dev/filippo.io/age offers a simple interface for 
encrypting/decrypting, with command line, too.

christoph...@gmail.com a következőt írta (2023. szeptember 20., szerda, 
10:02:24 UTC+2):

> Hello, 
>
> I noticed that the go standard library only support ed25519 signing (
> https://pkg.go.dev/crypto/ed2...@go1.21.1 
> ). 
>
> I would need to encrypt a small secret with the public key of the receiver 
> so that he is the only one able to decrypt it with its private key. The 
> small secret would typically be a random symmetric key used to encrypt the 
> possibly long message.  
>
> The only solution I found is to use nacl.Box (
> https://pkg.go.dev/golang.org/x/crypto/nacl/box). Why is it so ? 
>
> Are there alternative reliable go packages I could use ? I'll use only a 
> pure Go package, not a libsodium wrapper package. 
>
>
>

-- 
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/44f42db0-cbd5-4a36-ab38-a4ca7d9d09abn%40googlegroups.com.


[go-nuts] Re: [slog] customize defaultHandler

2023-08-29 Thread Tamás Gulácsi
Sorry for my wrong answer - I thought that should work.

https://go.dev//issues/61892 explains it: the default slog handler uses the 
default log.Logger.
This answers my other question, too: why is the default slog.Handler 
(newDefaultHandler) unexported? Because it's error prone.

https://go.dev/play/p/VmtpDveEapb

works as the workaround: log.SetOutput (after slog.SetDefault) breaks the 
cycle (but you have to set the default flags, too).

Mike Schinkel a következőt írta (2023. augusztus 29., kedd, 3:00:01 UTC+2):

> Hi Tamás,
>
> Have you actually tried that and gotten it to work? It does not compile
> for me but this does (note method call vs. property reference):
>
> slog.SetDefault(slog.New(myHandler{Handler:slog.Default().Handler()}))
>
> However, when delegating the Handle() method it seems to cause an infinite
> loop:
>
> func (m MyHandler) Handle(ctx context.Context, r slog.Record) error {
> return m.Handler.Handle(ctx, r)
> }
>
> See https://goplay.tools/snippet/qw07m0YflLd
>
> I know about this because just this past weekend I was trying to write a
> TeeHandler to output the default to the screen and JSON to a file just this
> past weekend and ran into an infinite loop problem with the default 
> handler.
>
> I tried my best to figure out why it needed to be structured the way it was
> in that it seems to call itself recursively. I wanted to post a question to
> this list to see if there was a workaround, or if not to see if there might
> be interest in allowing it to work, but I could not get my head around it 
> so
> eventually gave up and just used the TextHandler instead.
>
> Shame though. It would be nice to be able to reuse the default handler but
> AFACT it is not possible (though if I am wrong I would love for someone to
> show me how to get it to work.)
>
> -Mike
>
>
> On Monday, August 28, 2023 at 12:50:50 PM UTC-4 Tamás Gulácsi wrote:
>
> slog.SetDefault(slog.New(myHandler{Handler:slog.Default().Handler}))
>
> vl...@mailbox.org a következőt írta (2023. augusztus 28., hétfő, 15:06:37 
> UTC+2):
>
> Hi, 
>
> When reading trough the log/slog documentation, it seems one can create 
> a logger with a different handler, which is either NewTextHandler or 
> NewJSONHandler. 
>
> Why can't I configure the defaultHandler? Let's say I want my logger to 
> behave exactly like the defaultHandler, but output to a logfile or 
> Stdout instead. 
>
> The defaultHandler's output is different compared to the NewTextHandler: 
>
> slog.Info("ok"), gives me: 
>
> INFO ok 
>
> The NextTextHandler gives me: 
>
> level=INFO msg="ok" 
>
>
> Regards, 
>
>

-- 
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/97a5ffed-670b-418f-90f2-4532b7831a64n%40googlegroups.com.


[go-nuts] Re: [slog] customize defaultHandler

2023-08-28 Thread Tamás Gulácsi
slog.SetDefault(slog.New(myHandler{Handler:slog.Default().Handler}))

vl...@mailbox.org a következőt írta (2023. augusztus 28., hétfő, 15:06:37 
UTC+2):

> Hi,
>
> When reading trough the log/slog documentation, it seems one can create 
> a logger with a different handler, which is either NewTextHandler or 
> NewJSONHandler.
>
> Why can't I configure the defaultHandler? Let's say I want my logger to 
> behave exactly like the defaultHandler, but output to a logfile or 
> Stdout instead.
>
> The defaultHandler's output is different compared to the NewTextHandler:
>
> slog.Info("ok"), gives me:
>
> INFO ok
>
> The NextTextHandler gives me:
>
> level=INFO msg="ok"
>
>
> Regards,
>
>

-- 
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/09cba7f7-6109-4874-9ab3-1584771499cdn%40googlegroups.com.


Re: [go-nuts] Why is pdfcpu v0.5.0 290MiB on proxy.golang.org ?

2023-08-25 Thread Tamás Gulácsi
You're right, thanks.

Do you have any simple solution for this (beside deleting those files)?
Putting such files in a git submodule or git-LFS seems appropriate but 
complex.


Axel Wagner a következőt írta (2023. augusztus 25., péntek, 10:08:47 UTC+2):

> ISTM that's because they include a lot of PDFs for samples and test data 
> in their repository now:
> https://github.com/pdfcpu/pdfcpu/tree/master/pkg/samples (245 MB)
> https://github.com/pdfcpu/pdfcpu/tree/master/pkg/testdata (77 MB)
> This isn't due to the module mirror doing anything weird, it's just that 
> the module is now big because it includes tons of data it didn't use to.
>
> On Fri, Aug 25, 2023 at 9:53 AM Tamás Gulácsi  wrote:
>
>> go get github.com/pdfcpu/pdf...@v0.5.0 
>> <http://github.com/pdfcpu/pdfcpu@v0.5.0> hung, so I've investigated:
>>
>> $ go get -x github.com/pdfcpu/pdfcpu/pkg/api@latest
>> # get http://proxy.golang.org/github.com/@v/list   
>> # get http://proxy.golang.org/github.com/pdfcpu/pdfcpu/@v/list 
>> # get http://proxy.golang.org/github.com/pdfcpu/pdfcpu/pkg/api/@v/list   
>>   
>> # get http://proxy.golang.org/github.com/pdfcpu/pdfcpu/pkg/@v/list   
>> # get http://proxy.golang.org/github.com/pdfcpu/@v/list 
>> # get http://proxy.golang.org/github.com/@v/list: 404 Not Found (0.145s)
>> # get http://proxy.golang.org/github.com/pdfcpu/@v/list: 404 Not Found 
>> (0.145s) 
>> # get http://proxy.golang.org/github.com/pdfcpu/pdfcpu/pkg/@v/list: 404 
>> Not Found (0.149s)
>> # get http://proxy.golang.org/github.com/pdfcpu/pdfcpu/pkg/api/@v/list: 
>> 404 Not Found (0.149s)
>> # get http://proxy.golang.org/github.com/pdfcpu/pdfcpu/@v/list: 200 OK 
>> (0.150s)
>> go: downloading github.com/pdfcpu/pdfcpu v0.5.0  
>> # get http://proxy.golang.org/github.com/pdfcpu/pdfcpu/@v/v0.5.0.zip 
>> 
>>   
>>
>> $ curl -X HEAD -L -v 
>> http://proxy.golang.org/github.com/pdfcpu/pdfcpu/@v/v0.5.0.zip
>> < HTTP/2 302 Found
>> < Location: 
>> https://storage.googleapis.com/proxy-golang-org-prod/98db0a8de358d04c-github.com:pdfcpu:pdfcpu-v0.5.0.zip?Expires=1693035533=gcs-url
>> signer-prod%40golang-modproxy.iam.gserviceaccount.com
>> =Z6z%2FSzrSw6HYRQRAlZfRTB36whErbhGl4rVFBnnR%2FRG0J14GUYiFXHsk%2FmMPRJAIqcgdQZ0vND4QQ%2FRlJaS6AE4
>>
>> RQtwhqDx6pCJn6%2FTPbVUaVBPgEdWppd2x5r1%2BR1eOn54VjE%2BNWZ0LKT9IOCwLN9oWjZPQrz1WnPfKn7vZIc3E5MQd%2FxnZ8foQBfNEJ6WgNFcD6QzUlNRSJkZk8EPa8G7hsAEwZKLwI1GgfIWwtWgd2G
>> We%2FqpUOqxdPhSorKlJqVGovpVY4n9QTHPRXJGqrXKSaCDZohdIK%2B%2FNklGctIXlK57HNMmzAatyETAOx5kCIfeL3PTxCWszixjy1PkZQA%3D%3D
>>  
>>   
>> < HTTP/2 200 
>> < x-guploader-uploadid: 
>> ADPycdv391ZoUD64eO_-_QY6cAnAFZIdoaseg8u0fxxTTCD9kyNMn8g8cYd_mB3k1HNHMBOF_dxn9d36p_hNjHbTCYaCOw
>> < date: Fri, 25 Aug 2023 07:47:24 GMT
>> < cache-control: public,max-age=3600,must-revalidate
>> < expires: Fri, 25 Aug 2023 08:47:24 GMT
>> < last-modified: Sun, 20 Aug 2023 12:49:28 GMT
>> < etag: "2396accaf05435436ab40e7eee3700f1"
>> < x-goog-generation: 1692535768254742
>> < x-goog-metageneration: 1
>> < x-goog-stored-content-encoding: identity
>> < x-goog-stored-content-length: 293287851
>> < content-type: application/zip
>> < content-disposition: attachment; filename="v0.5.0.zip"
>> < x-goog-hash: crc32c=61bZnw==
>> < x-goog-hash: md5=I5asyvBUNUNqtA5+7jcA8Q==
>> < x-goog-storage-class: MULTI_REGIONAL
>> < accept-ranges: bytes
>> < content-length: 293287851
>> < server: UploadServer
>> < alt-svc: h3=":443"; ma=2592000,h3-29=":443"; ma=2592000
>>
>>
>> ??
>>
>> v0.4.2 is just 3MiB.
>>
>> -- 
>> 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/00c8d89f-5d7c-47f7-810b-68ee6046b995n%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/golang-nuts/00c8d89f-5d7c-47f7-810b-68ee6046b995n%40googlegroups.com?utm_medium=email_source=footer>
>> .
>>
>

-- 
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/8b0f6828-ab41-4f82-a117-d6a11f4b827bn%40googlegroups.com.


[go-nuts] Why is pdfcpu v0.5.0 290MiB on proxy.golang.org ?

2023-08-25 Thread Tamás Gulácsi
go get github.com/pdfcpu/pdfcpu@v0.5.0 hung, so I've investigated:

$ go get -x github.com/pdfcpu/pdfcpu/pkg/api@latest
# get http://proxy.golang.org/github.com/@v/list   
# get http://proxy.golang.org/github.com/pdfcpu/pdfcpu/@v/list 
# get http://proxy.golang.org/github.com/pdfcpu/pdfcpu/pkg/api/@v/list 

# get http://proxy.golang.org/github.com/pdfcpu/pdfcpu/pkg/@v/list   
# get http://proxy.golang.org/github.com/pdfcpu/@v/list 
# get http://proxy.golang.org/github.com/@v/list: 404 Not Found (0.145s)
# get http://proxy.golang.org/github.com/pdfcpu/@v/list: 404 Not Found 
(0.145s) 
# get http://proxy.golang.org/github.com/pdfcpu/pdfcpu/pkg/@v/list: 404 Not 
Found (0.149s)
# get http://proxy.golang.org/github.com/pdfcpu/pdfcpu/pkg/api/@v/list: 404 
Not Found (0.149s)
# get http://proxy.golang.org/github.com/pdfcpu/pdfcpu/@v/list: 200 OK 
(0.150s)
go: downloading github.com/pdfcpu/pdfcpu v0.5.0  
# get http://proxy.golang.org/github.com/pdfcpu/pdfcpu/@v/v0.5.0.zip   



$ curl -X HEAD -L -v 
http://proxy.golang.org/github.com/pdfcpu/pdfcpu/@v/v0.5.0.zip
< HTTP/2 302 Found
< Location: 
https://storage.googleapis.com/proxy-golang-org-prod/98db0a8de358d04c-github.com:pdfcpu:pdfcpu-v0.5.0.zip?Expires=1693035533=gcs-url
signer-prod%40golang-modproxy.iam.gserviceaccount.com=Z6z%2FSzrSw6HYRQRAlZfRTB36whErbhGl4rVFBnnR%2FRG0J14GUYiFXHsk%2FmMPRJAIqcgdQZ0vND4QQ%2FRlJaS6AE4
RQtwhqDx6pCJn6%2FTPbVUaVBPgEdWppd2x5r1%2BR1eOn54VjE%2BNWZ0LKT9IOCwLN9oWjZPQrz1WnPfKn7vZIc3E5MQd%2FxnZ8foQBfNEJ6WgNFcD6QzUlNRSJkZk8EPa8G7hsAEwZKLwI1GgfIWwtWgd2G
We%2FqpUOqxdPhSorKlJqVGovpVY4n9QTHPRXJGqrXKSaCDZohdIK%2B%2FNklGctIXlK57HNMmzAatyETAOx5kCIfeL3PTxCWszixjy1PkZQA%3D%3D
 
  
< HTTP/2 200 
< x-guploader-uploadid: 
ADPycdv391ZoUD64eO_-_QY6cAnAFZIdoaseg8u0fxxTTCD9kyNMn8g8cYd_mB3k1HNHMBOF_dxn9d36p_hNjHbTCYaCOw
< date: Fri, 25 Aug 2023 07:47:24 GMT
< cache-control: public,max-age=3600,must-revalidate
< expires: Fri, 25 Aug 2023 08:47:24 GMT
< last-modified: Sun, 20 Aug 2023 12:49:28 GMT
< etag: "2396accaf05435436ab40e7eee3700f1"
< x-goog-generation: 1692535768254742
< x-goog-metageneration: 1
< x-goog-stored-content-encoding: identity
< x-goog-stored-content-length: 293287851
< content-type: application/zip
< content-disposition: attachment; filename="v0.5.0.zip"
< x-goog-hash: crc32c=61bZnw==
< x-goog-hash: md5=I5asyvBUNUNqtA5+7jcA8Q==
< x-goog-storage-class: MULTI_REGIONAL
< accept-ranges: bytes
< content-length: 293287851
< server: UploadServer
< alt-svc: h3=":443"; ma=2592000,h3-29=":443"; ma=2592000


??

v0.4.2 is just 3MiB.

-- 
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/00c8d89f-5d7c-47f7-810b-68ee6046b995n%40googlegroups.com.


[go-nuts] Re: Download large Zip file via sftp

2023-08-23 Thread Tamás Gulácsi
Possibly it's a concurrency error in the sftp library you're using.
Compile with "-race" flag and test it - it should print out the offending 
code.

Phillip Siessl a következőt írta (2023. augusztus 23., szerda, 14:37:10 
UTC+2):

> Hi 
>
> i have some issues when i try to download a larger zip file (5GB) via the 
> sftp package in go. 
> about 20% of the time it runs through smoothly but the other 80% i get a 
> panic with
> "fatal error: concurrent map writes writing to file" or "fatal error: 
> concurrent map read and map write".
>
> this is the code for the download function: 
>
> func DownloadZip(sc sftp.Client, remoteFile, localFile string) (err error) 
> {
>
> fmt.Fprintf(os.Stdout, "Downloading [%s] to [%s] ...\n", remoteFile, 
> localFile)
> srcFile, err := sc.OpenFile(remoteFile, (os.O_RDONLY))
> if err != nil {
> fmt.Fprintf(os.Stderr, "Unable to open remote file: %v\n", err)
> return
> }
>
> defer srcFile.Close()
> fmt.Println("Create locale file")
> dstFile, err := os.Create(localFile)
> if err != nil {
> fmt.Fprintf(os.Stderr, "Unable to open local file: %v\n", err)
> return
> }
> defer dstFile.Close()
> fmt.Println("Copy remote file")
> bytes, err := io.Copy(dstFile, srcFile)
> if err != nil {
> fmt.Fprintf(os.Stderr, "Unable to download remote file: %v\n", err)
> os.Exit(1)
> }
> fmt.Println("Save local file")
> fmt.Fprintf(os.Stdout, "%d bytes copied\n", bytes)
>
> return
> }
>
>
> If anybody has some ideas i would be very happy. thx
>
>

-- 
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/c0c72354-e386-4cbd-9534-f9fd1e639455n%40googlegroups.com.


Re: [go-nuts] What happened to sep in errorrs.join

2023-08-09 Thread Tamás Gulácsi
Strange. AFAIK the JSON handler escapes the \n in strings.

Joseph Lorenzini a következőt írta (2023. augusztus 8., kedd, 13:24:56 
UTC+2):

> Thanks that was very helpful. As for your point about slog, yes a custom 
> handler could but I am using the library json handler.
>
> I suppose the proper way to frame my problem is that I am using the slog 
> library handler and I do not want new lines in the message or keys. 
>
> Would the go team would be open to providing knobs to control how the 
> handler does formatting? I assumed if I tried opening a proposal like that 
> I’d be told to write a custom handler. :) 
>
> On Mon, Aug 7, 2023 at 3:56 PM Ian Lance Taylor  wrote:
>
>> On Mon, Aug 7, 2023 at 4:32 AM jal...@gmail.com  wrote:
>> >
>> > In the errors.join proposal, the proposed api had the user specify how 
>> they wanted the errors to be formatted together. But the actual 
>> implementation omitted and only used new line.
>> >
>> > This is quite unfortunate if you are using slog and want to log that 
>> error and very much need a log statement to not span multiple lines. It 
>> also makes it much harder to read.
>> >
>> > Does anyone recall why sep was dropped?
>>
>> See the discussion at https://go.dev/issue/53435, especially
>> https://github.com/golang/go/issues/53435#issuecomment-1190654775 and
>> https://github.com/golang/go/issues/53435#issuecomment-1190845424.
>>
>> As far as the slog package it seems to me that a handler can enforce
>> that individual messages are on a single line.  There may be a better
>> way to address that problem, but I don't think that errors.Join is the
>> right place for a fix.  Any random package can generate multiline
>> error messages with errors.New("a\nb"), and I've seen plenty that do.
>> So enforcing single-line messages on errors.Join won't fix the problem
>> in general.
>>
>> 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/e49a8b4e-571a-4641-b3e9-8ef98716d03an%40googlegroups.com.


[go-nuts] Re: How to convert an svg to a png (or gif) image?

2023-08-04 Thread Tamás Gulácsi
https://pkg.go.dev/github.com/goki/gi/svg

Mark a következőt írta (2023. augusztus 3., csütörtök, 13:18:48 UTC+2):

> I know this has been asked before, just wondered if there were any pure-Go 
> solutions?
>

-- 
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/d65b7fcc-bfaa-4d29-9332-bfaf0c004bedn%40googlegroups.com.


[go-nuts] Re: How do library functions that accept a context implement context cancellation inside?

2023-07-21 Thread Tamás Gulácsi
It depends. Checking the context (btw "if err := ctx.Err(); err != nil { 
return err }" is enough, no need for "select")
is cheap but not free. So partition for reasonable sized chunks of work.

Tamás

Gurunandan Bhat a következőt írta (2023. július 21., péntek, 9:21:15 UTC+2):

> Sorry - I meant ..."calling select once per line" be a good point
>
> On Fri, Jul 21, 2023 at 12:41 PM Gurunandan Bhat  wrote:
>
>> Hi, 
>>
>> Are there any common patterns that standard and 3rd party library 
>> functions use to implement cancelling a context passed to it? I have looked 
>> at the source of exec.CommandContext and it starts the process and spawns a 
>> goroutine that kills the process when ctx.Done() is closed. That looks 
>> simple enough. 
>>
>> It seems to me that the key to implementing cancellation enabled function 
>> is to look at specific points inside the function where ctx.Done() is 
>> checked for. As an example, if I want to create a cancellable function that 
>> reads lines from a file, would select'ing on ctx.Done() be a good place?
>>
>> 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/134fe37d-4c8b-4360-934a-6b89c37bc581n%40googlegroups.com.


Re: [go-nuts] Export fs.FS as FUSE fs

2023-06-29 Thread Tamás Gulácsi
FS is an abstraction, a common interface for file systems. 
It allows me to provide access to an archive (zip, tar) or database or 
network (S3, HTTP ...) backed file system.
Thus exporting FS as a FUSE filesystem allows all those FS implementations 
to be accessed as a real file system,
eliminating the double implementation (say, if you implement a HTTP backed 
FS, you can use it as a FUSE fs, don't have to reimplement it with a fuse 
lib).

You're right, exporting a file system backed FS as FUSE is moot.
But exporting the embed.FS or database backed FS as FUSE allows ordinary 
programs, user, scripts to access those files.

FS being read-only is a bless and a curse at the same time: simplifies 
implementation, but deflates the usefulness.
Roland Müller a következőt írta (2023. június 29., csütörtök, 9:00:18 
UTC+2):

> Hello,
> I am struggling to understand the purpose of extension. 
> FS is an interface to access file systems from go code. Is your new 
> extension acting as a handler and allows to expose any Go FS to be mounted 
> and acessed at operating system level?
>
>
> https://en.m.wikipedia.org/wiki/Filesystem_in_Userspace#/media/File%3AFUSE_structure.svg
>
> Br/Üdvözlettel
> Roland
>
> Am Samstag, 24. Juni 2023 schrieb Tamás Gulácsi :
> > Ok, I've put some hours into it, and implemented it: 
> https://pkg.go.dev/github.com/tgulacsi/g...@v0.25.0/fsfuse 
> <https://pkg.go.dev/github.com/tgulacsi/go@v0.25.0/fsfuse>
> > It uses github.com/jacobsa/fuse to export a mountable io/fs.FS.
> > I've only tested with os.DirFS, with that, it works as expected.
> > I'd love to get some feedback - if anynone interested, I can export it 
> to some more direct/slimmer repo.
> > Tanás Gulácsi
> >
> > Tamás Gulácsi a következőt írta (2023. június 23., péntek, 8:08:32 
> UTC+2):
> >>
> >> Hi,
> >> Does anyone know an existing solution for exporting an fs.FS as a FUSE 
> filesystem?
> >> As fs.FS is standard now, this would open several new possibilities,
> >> as a lot of interesting fs.FS implementations exist (zip, tar, DB, 
> embedded, union ),
> >> and this one little glue code could export them all!
> >> Thanks in advance,
> >> Tamás
> >
> > --
> > 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/f8edf7e1-a864-4ab0-b7e6-773246485da1n%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/8f8b61ab-9975-4bb3-8f09-0a5c2f3a07adn%40googlegroups.com.


[go-nuts] Re: Export fs.FS as FUSE fs

2023-06-24 Thread Tamás Gulácsi
Ok, I've put some hours into it, and implemented it: 
https://pkg.go.dev/github.com/tgulacsi/go@v0.25.0/fsfuse
It uses github.com/jacobsa/fuse to export a mountable io/fs.FS.

I've only tested with os.DirFS, with that, it works as expected.

I'd love to get some feedback - if anynone interested, I can export it to 
some more direct/slimmer repo.

Tanás Gulácsi

Tamás Gulácsi a következőt írta (2023. június 23., péntek, 8:08:32 UTC+2):

> Hi,
>
> Does anyone know an existing solution for exporting an fs.FS as a FUSE 
> filesystem?
>
> As fs.FS is standard now, this would open several new possibilities,
> as a lot of interesting fs.FS implementations exist (zip, tar, DB, 
> embedded, union ),
> and this one little glue code could export them all!
>
> Thanks in advance,
> Tamás
>

-- 
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/f8edf7e1-a864-4ab0-b7e6-773246485da1n%40googlegroups.com.


[go-nuts] Export fs.FS as FUSE fs

2023-06-23 Thread Tamás Gulácsi
Hi,

Does anyone know an existing solution for exporting an fs.FS as a FUSE 
filesystem?

As fs.FS is standard now, this would open several new possibilities,
as a lot of interesting fs.FS implementations exist (zip, tar, DB, 
embedded, union ),
and this one little glue code could export them all!

Thanks in advance,
Tamás

-- 
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/6d5100d8-04b7-4b22-a0df-77837de2f4f5n%40googlegroups.com.


[go-nuts] Re: Unit testing slog output

2023-06-14 Thread Tamás Gulácsi
github.com/UNO-SOFT/zlog/v2 
NewT(t).SLog()
returns an *slog.Logger that uses t.Log for printing.

But maybe I don't understand your real problem.

shan...@gmail.com a következőt írta (2023. június 14., szerda, 2:14:27 
UTC+2):

> In the past when I wanted to 'capture' the log output so that I could 
> check it in a unit test I would 'hijack' os.Stdout like so
> ```
> var osStdout = os.Stdout
> func MyCode (){
>   log.SetOutput(osStdout)
>   log.Print("My dog has fleas")
> }
> ```
> Which could then be tested thus
> ```
> func TestMyCode(t *testing.T){
>   testcases := map[string]struct{
>   output string
>   }{
> "Dog needs flea shampoo": {
>   output: "My dog has fleas",
> },
>   }
>   for name, tc := range testcases {
>   t.Run(name, func(t *testing.T) {
>  orig := osStdout
>  flags := log.Flags()
>  log.SetFlags(0)
>  reader, writer, err := os.Pipe()
>  if err != nil {
> panic(err)
>  }
>  osStdout = writer
>  defer func() {
>osStdout = orig
>log.SetFlags(flags)
>   }()
>  MyCode()
>  writer.Close()
>
>  var buf strings.Builder
>  if _, ioerr := io.Copy(, reader); ioerr != nil {
>log.Fatalf("Copy error, cannot continue %v\n", ioerr)
>  }
>
>   assert.Equal(t, tc.output, buf.String(), "Expected: %s Got: %s", 
> tc.output, buf.String())
>  }
>})
> }
> }
> ```
>
> I'm now trying to do the same with the slog package (but not having any 
> joy) - is there an established pattern that people are using, eg. is the 
> handler being
>
> I've been trying 
> ```
> func TestMyCode(t *testing.T){
>   testcases := map[string]struct{
>   output string
>   }{
> "Dog needs flea shampoo": {
>   output: "My dog has fleas",
> },
>   }
>   for name, tc := range testcases {
>   t.Run(name, func(t *testing.T) {
>  orig := osStdout
>  reader, writer, err := os.Pipe()
>  if err != nil {
> panic(err)
>  }
>  osStdout = writer
>  defer func() {
>osStdout = orig
>   }()
>  slog.SetDefault(slog.New(slog.NewTextHandler(osStdout)
>  MyCode()
>  writer.Close()
>
>  var buf strings.Builder
>  if _, ioerr := io.Copy(, reader); ioerr != nil {
>log.Fatalf("Copy error, cannot continue %v\n", ioerr)
>  }
>
>   assert.Equal(t, tc.output, buf.String(), "Expected: %s Got: %s", 
> tc.output, buf.String())
>  }
>})
> }
> }
> ```
>
> Which "works" but I am not happy with it, because it's affecting all of 
> the slog instances.
>
> I saw previously that someone was creating their own implementation of a 
> slog.Handler? to make testing easier, and would love to see it, and will 
> that allow me to run multiple slog based tests concurrently?
>

-- 
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/9f9449cd-b04b-4b9f-b7ce-639e80e7a708n%40googlegroups.com.


[go-nuts] Re: smarter way to provide interface capabilities from underlining interface

2023-06-11 Thread Tamás Gulácsi
As Far as I See, you check all the combinations of methods in wideness 
order.
Why not have a generic wrapper struct, that is filled with the underlying 
driver.Conn's methods, 
and use that if not nil, but use the generic implementation if not.

Like
```
type wrappedConn struct {
  driver.Conn
  queryContext func(...)
}
func (wc wrappedConn) QueryContext(...) ... {
  if wc.queryContext != nil { return wc.queryContext(...) }
  return wc.Conn.Query(...)
}
```

This way you only have to check for each method on driver.Conn, and fill 
the wrappedConn's functions as they axist/not.

Vasiliy Tolstov a következőt írta (2023. június 10., szombat, 12:16:34 
UTC+2):

> I have sql driver that wraps original driver.Driver, to be able to work 
> with drivers that not have ExecerContext or QuerierContext i need to return 
> wrapped to that supports only needed interfaces.
> I'm to want to write all cases via handmade switch case and write 
> generator that creates full combo list of methods and generate interfaces 
> for this methods.
> But this brings file that contains 20K lines 
> https://git.unistack.org/unistack-org/micro-wrapper-sql/src/branch/master/wrap_gen.go
> Does it possible to have smaller code that provides the same effect?
> Or I'm miss something?
>
> -- 
> Vasiliy Tolstov,
> e-mail: v.to...@selfip.ru
>

-- 
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/711d305c-7c4b-405e-9932-74dcc1ae8603n%40googlegroups.com.


[go-nuts] Re: Why does os.RemoveAll ignore ErrNotExists?

2023-04-24 Thread Tamás Gulácsi
You want that path to be fully removed.
If it does not exist, then it's already done, nothing to do, the desired 
result has been achieved (already).

xiaq a következőt írta (2023. április 24., hétfő, 16:42:22 UTC+2):

> Hi,
>
> The os.RemoveAll function  does not 
> return an error when the path doesn't exist. Given that this is documented 
> explicitly and implemented using an explicit check 
> ,
>  
> this seems to be a conscious design choice rather than an accidental 
> implementation detail.
>
> Does anybody know what the rationale behind this is? I haven't been able 
> to find any information in this forum or elsewhere.
>

-- 
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/414a68c6-1f7c-4703-865f-77288dadb993n%40googlegroups.com.


[go-nuts] Re: Ask about Golang Behavior

2023-03-20 Thread Tamás Gulácsi
You should print cap(newMessage.Biawaks).
A nil slice cannot have non-zero capacity.
A nil slice and a zero-length slice is semantically equivalent.

febriananda pramudita a következőt írta (2023. március 20., hétfő, 16:44:54 
UTC+1):

> I was playing with protobuf marshaller recently and found this behavior
>
> https://gist.github.com/FwP-pintu/448f8ecddf27987a7e5b8a103eda12cb
>
> Is behavior: "nil slice with more than 0 capacity" is intended? Thank you.
>
>

-- 
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/bcf6d5b2-3706-4aaf-8ec3-0b2c195cfef2n%40googlegroups.com.


Re: [go-nuts] Re: Looking for a specialized proxy package

2023-03-16 Thread Tamás Gulácsi
As far as I understand, the requirement is to have a link presented by the 
cloud server, that is proxied to the IOT's HTTP handler.
The latter is only on the IOT's localhost, accessible on the cloud server 
through ssh reverse tunneling (so, a specific port on the cloud server's 
localhost).
This is easy: just have a handler on the cloud server (say, 
/p/) that 
1. looks up the unique id and fetches the proper 
http://localhost:permanent-port.
2. The hard part is that you have to rewrite each URL in each response, 
otherwise the links and imports won't work.

All this can be achieved with net/http/httputil#ReversProxy, with proper 
Rewrite (for 1.) and ModifyResponse (for 2.) methods.

2. may be elided by putting the IOT under a subdomain on the server  - but 
this needs * SSH certificate (or Let'sEncrypt  - Caddy may help).

GT
Vladimir Varankin a következőt írta (2023. március 16., csütörtök, 9:03:53 
UTC+1):

> Hey Michael,
>
> > The piece I'm missing is how to construct a proxying handler that will 
> use the identifier in the link to look up the tunnel port and fetch the 
> IOT's home page and thereafter make it seem as though the user is directly 
> browsing the IOT.
>
> If I got the question right, there are two parts:
>
> 1. Build an HTTP reverse proxy, which routes the requests to a target 
> device's server (i.e. the upstream).
>
> Go's httputil.ReverseProxy (
> https://pkg.go.dev/net/http/httputil#ReverseProxy) can do that. You will 
> need to implement httputil.ReverseProxy.Rewrite to route a request.
>
> 2. Use the identifier in the link to look up the tunnel port 
>
> Not sure, if I've missed what "link" means in this context — is this a 
> network interface, the devices are connected to?
>
> On Thursday, March 16, 2023 at 2:17:09 AM UTC+1 Michael Ellis wrote:
>
>> Thanks, Matthew.  I know what RPC is, but have never considered it as a 
>> way to serve http from behind a NAT.  I should say that the IOT's are part 
>> of a product that's been in the market for several years.  My client likes 
>> the web interface we built and wants users to be able to access an IOT's 
>> pages through a secure intermediary server.  How would that work with grpc?
>>
>> On Wednesday, March 15, 2023 at 7:08:04 PM UTC-4 Matthew Zimmerman wrote:
>>
>>> Honestly I'd probably use grpc and keep a constant connection from the 
>>> IOT to the cloud.  No ports/services required on the client at all and the 
>>> server can still request things in real time.
>>>
>>> Like: 
>>> https://www.talentica.com/blogs/part-3-building-a-bidirectional-streaming-grpc-service-using-golang/
>>>
>>> On Wed, Mar 15, 2023, 6:35 PM Michael Ellis  
>>> wrote:
>>>
 FWIW,  I pasted my  post into ChatGPT-4 and got what might be a 
 plausible outline of an approach using 
 httputil.NewSingleHostReverseProxy.

 But, as we know, LLM's are prone to hallucination. If you're curious, 
 here's a share link. 

 https://shareg.pt/cNoNdWc

 On Wednesday, March 15, 2023 at 5:57:48 PM UTC-4 Michael Ellis wrote:

> I posted a question about this on ServerFault 
> last
>  
> week but didn't get any answers other than a few comments from one person 
> who said (basically) "use a VPN".   That seems like overkill.  I'm trying 
> to find a reliable way to proxy occasional HTTP access to any of  ~100 
> geographically dispersed IOT devices through a cloud server.  
>
> I'm using Go on the cloud server and on the IOT devices, so I thought 
> I'd ask here.
>
> *Situation:*
>
>- We have complete control over the configuration of the IOT 
>devices and the cloud host.
>- We don't have control of the customers' routers and firewalls, 
>but can specify minimum requirements for port openings, etc.
>- FWIW, the IOT devices are BeagleBone Black running Debian Buster 
>and the cloud host will be, typically, a multi-core droplet (or 
> similar) 
>running Linux.
>- The IOT's serve dynamic web pages over HTTP. (HTTPS doesn't seem 
>feasible because of certificate requirements and overall load on the 
> IOT 
>cpu.) The cloud host will have HTTPS capability.
>- This is a low-traffic situation. The IOT's report some overall 
>status information (via rsync/ssh) at 4 minute intervals). We already 
> have 
>a web interface (written in Go) on the cloud server that aggregates 
> and 
>displays the status reports.
>- Access to an IOT's web service will only occur when a user wants 
>to investigate a problem report in more detail. Typically, only one or 
> two 
>users will have credentials to browse the cloud server.
>
> The scheme I have in mind is: 
>
>1. At configuration time for each IOT device the installation tech 
>will 

[go-nuts] Re: Import files with extensions .xls and .xlsx .

2023-02-07 Thread Tamás Gulácsi
Yes, with github.com/extrame/xls and github.com/xuri/excelize/v2 .

aadityasha...@gmail.com a következőt írta (2023. február 8., szerda, 
7:29:22 UTC+1):

> Is it possible to import files with extensions .xls and .xlsx with go ?

-- 
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/9ea5ae02-9a39-4967-8bb3-5fdde5a23b23n%40googlegroups.com.


Re: [go-nuts] CGO core dump analysis using GDB

2023-01-09 Thread Tamás Gulácsi
I'd create a separate C program, that can be communicated with RPC style - 
(https://github.com/protobuf-c/protobuf-c-rpc may solve it easily),
and have the Go program start it like 
https://github.com/hashicorp/go-plugin .

That way the stack traces and core dumps are separate, each program is 
easier to debug,
the C error does not take down the Go program, which can restart the plugin 
...

mariappa...@gmail.com a következőt írta (2023. január 9., hétfő, 10:20:28 
UTC+1):

> Hi Ian,
>
> Thanks. I will try this. When a process is crashed because of a 
> SEGMENTATION fault, it can be debugged by identifying the stack trace from 
> the core dump. Is there any other technique to debug this issue? Can you 
> please help if any other technique is there?
>
> Best Regards
> Mariappan
>
> On Mon, Jan 9, 2023 at 12:07 PM Ian Lance Taylor  wrote:
>
>> On Sun, Jan 8, 2023, 9:33 PM mariappan balraj  
>> wrote:
>>
>>> Hi Ian,
>>>
>>> Thanks for all your replies. It really shows that you have tried to give 
>>> your best all the time. I need some direction to get a permanent solution 
>>> for this. Is it possible to get help from the core google GO team? How to 
>>> escalate this issue and get the fix? Please give me directions. So that I 
>>> can try best from my side.
>>>
>>
>> I'm on the core Google Go team myself.
>>
>> The next step is to file a bug report at https://go.dev/issue, with 
>> exact details for how to reproduce the problem.  But I don't want to 
>> mislead you: it's unlikely that anybody on the core Go team is going to fix 
>> this.  That said, Go is an open source project, and filing a bug report is 
>> the right step to encourage someone to fix the problem.
>>
>> It's also worth taking a step back and describing the real problem.  
>> Using gdb to get a stack trace from a core dump is a technique, it's not a 
>> solution.  Perhaps there are other techniques.
>>
>> Ian
>>
>>
>>
>>> On Sat, Jan 7, 2023 at 10:29 PM Ian Lance Taylor  
>>> wrote:
>>>
 On Fri, Jan 6, 2023 at 9:01 PM mariappan balraj
  wrote:
 >
 > Thanks for your continuous support. GOLANG supports CGO to invoke C 
 functions. When it is supported, the important thing is, it should provide 
 better debugging support when there is any issue. In customer sites, it is 
 not possible to run applications with GDB. Customers only provide core 
 dump 
 and logs. With the provided information, we should be able to debug the 
 issue. It may not be possible to reproduce all the issues in the 
 development environment to debug the issue.
 >
 > When we run the application with GDB, we are getting stack trace. 
 Then the same thing should be possible with core dump also.
 >
 > I have tried with CGO symbolizer from 
 https://github.com/ianlancetaylor/cgosymbolizer. I am getting the 
 following output. This is useful. But I want to dump the C variables 
 (local 
 and global) to debug the issue. This is very critical when we want to 
 debug 
 some issues.
 >
 > What should I do now? How to proceed further? If possible, please 
 provide your help with this.

 I'm sorry, I don't have any useful suggestions.  It's possible in
 principle to unwind the stack yourself by looking carefully at the
 instructions that will be executed and the PC and SP registers, and
 then to look at the instructions to figure out where variables are
 stored, but it's hard and it's easy to make a mistake.

 Ian


 > fatal error: unexpected signal during runtime execution
 > [signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x463926]
 >
 > runtime stack:
 > runtime.throw({0x49046b?, 0x0?})
 > /usr/local/go/src/runtime/panic.go:1047 +0x5d fp=0x7ffca8644230 
 sp=0x7ffca8644200 pc=0x43243d
 > runtime.sigpanic()
 > /usr/local/go/src/runtime/signal_unix.go:819 +0x369 fp=0x7ffca8644280 
 sp=0x7ffca8644230 pc=0x446569
 >
 > goroutine 1 [syscall]:
 > test1
 > /home/ubuntu/mbalraj/GO/TEST/test.go:9 pc=0x463926
 > test2
 > /home/ubuntu/mbalraj/GO/TEST/test.go:14 pc=0x46393b
 > test3
 > /home/ubuntu/mbalraj/GO/TEST/test.go:18 pc=0x46394b
 > _cgo_64d258852278_Cfunc_test3
 > /tmp/go-build/cgo-gcc-prolog:49 pc=0x46396b
 > runtime.asmcgocall
 > /usr/local/go/src/runtime/asm_amd64.s:844 pc=0x45c443
 > runtime.cgocall(0x46394f, 0xc58f70)
 > /usr/local/go/src/runtime/cgocall.go:158 +0x5c fp=0xc58f48 
 sp=0xc58f10 pc=0x40579c
 > main._Cfunc_test3()
 > _cgo_gotypes.go:41 +0x45 fp=0xc58f70 sp=0xc58f48 pc=0x463885
 > main.main()
 > /home/ubuntu/mbalraj/GO/TEST/test.go:26 +0x17 fp=0xc58f80 
 sp=0xc58f70 pc=0x4638b7
 > runtime.main()
 > /usr/local/go/src/runtime/proc.go:250 +0x212 fp=0xc58fe0 
 sp=0xc58f80 pc=0x434c92
 > runtime.goexit()
 > /usr/local/go/src/runtime/asm_amd64.s:1594 

[go-nuts] Re: json encoder with large object (big bytes array)

2022-12-10 Thread Tamás Gulácsi
Not directly, but you can implement sth akin: 
https://go.dev/play/p/vN2uAp9rRpp
With reflection, you can build a helper that uses the exposed MarshalInto 
on types that implement it,
and falls back to Marshal otherwise.

jerome@gmail.com a következőt írta (2022. december 10., szombat, 
8:31:26 UTC+1):

> Hello,
> I would like to know if there is elegant way to json encode very long 
> field (with io.Reader)?
>
> For example: (play ground https://go.dev/play/p/QxlbNMy3ERK )
> ```
> func TestJSONStreamBytes(t *testing.T) {
> type MyStruct struct {
> Reader1 io.Reader `json:"field1"`
> Reader2 io.Reader `json:"field2"`
> }
>
> out := {}
>
> err := json.NewEncoder(out).Encode(MyStruct{
> Reader1: strings.NewReader("this stream can be very long from S3 
> Bucket for example"),
> Reader2: strings.NewReader("this stream can be very long from 
> another S3 Bucket for example"),
> })
> if err != nil {
> panic(err)
> }
>
> t.Log(out.String())
> }
> ```
> It returns prog.go:29: {"field1":{},"field2":{}}
>
> But I want base64encoded response managed as stream mode (i.e. I don't 
> want to load the data in our memory) like :
>
>
> {"field1":"dGhpcyBzdHJlYW0gY2FuIGJlIHZlcnkgbG9uZyBmcm9tIFMzIEJ1Y2tldCBmb3IgZXhhbXBsZQ==","field2":"dGhpcyBzdHJlYW0gY2FuIGJlIHZlcnkgbG9uZyBmcm9tIGFub3RoZXIgUzMgQnVja2V0IGZvciBleGFtcGxl"}
>
>
> Thank in advance,
> Jérôme
>

-- 
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/b14b47af-fea8-4c21-8dbb-013ee30201b3n%40googlegroups.com.


Re: [go-nuts] Re: go:embed question

2022-10-15 Thread Tamás Gulácsi
It won't work iff that file is not there - e.g. it is not commited into the 
repo.

kortschak a következőt írta (2022. október 14., péntek, 10:50:18 UTC+2):

> On Fri, 2022-10-14 at 00:17 -0700, esimov wrote:
> > . Now, that's not the case when you are running a package using the
> > following command: "go run github.com/user/package@latest" for
> > example
>
> Can you give an example of a real package where this doesn't work?
>
>

-- 
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/4e3a43d4-603c-458d-844e-fa156dc76042n%40googlegroups.com.


[go-nuts] Re: Error-checking with errors.As() is brittle with regards to plain vs pointer types

2022-09-22 Thread Tamás Gulácsi
plain struct error is brittle in other ways, too: you can shoot yourself on 
foot with "err != nil" check.
So: error should be a pointer type.

cpu...@gmail.com a következőt írta (2022. szeptember 21., szerda, 21:26:31 
UTC+2):

> Consider https://go.dev/play/p/jgPMwLRRsqe:
>
> errors.As(err, ) will not match if error is of pointer type. 
> As a result, a library consumer needs to understand if a library returns 
> Error or *Error. However, that is not part of the API spec as both returns 
> would satisfy error if Error() is implemented on the plain type.
>
> A potential workaround would be using Error.As(any) to match plain/pointer 
> type as part of the library. However, it seems counterintuitive having to 
> do so if errors.As() doesn't by default.
>
> Would it make sense (and I would like to propose) to expand errors.As() to 
> match plain receiver types even when err is a pointer to the same 
> underlying plain type.
>
> What do you think?
>
> Cheers,
> Andi
>

-- 
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/b9d94e2f-860e-44eb-9f9e-efcd0a82b7d2n%40googlegroups.com.


Re: [go-nuts] Using golang variable in bash script Command

2022-09-19 Thread Tamás Gulácsi
No, please, no!

Do NOT use bash with string interpolation if possible!
Call find directly:
*cmd, err := exec.Command("find", ".", "-name", search)*
princ...@gmail.com a következőt írta (2022. szeptember 19., hétfő, 12:04:32 
UTC+2):

> then we don't need to add these commands 
>
>
>
> *scanner := bufio.NewScanner(os.Stdin)fmt.Println("Enter the substring 
> name")scanner.Scan()search:=scanner.Text()*
>  right???
>
> we only need to keep this one
>  *cmd, err := exec.Command("bash", "-c", fmt.Sprintf("find . -name %s", 
> search))*
>
> On Monday, September 19, 2022 at 3:31:12 PM UTC+5:30 Jan Mercl wrote:
>
>> On Mon, Sep 19, 2022 at 11:50 AM PK  wrote:
>>
>> > search:=scanner.Text()
>> > cmd1,err:=exec.Command("bash", "-c", "find . -name '*$search*'")
>>
>> Try something like this, not tested:
>>
>> cmd, err := exec.Command("bash", "-c", fmt.Sprintf("find . -name 
>> %s", search))
>>
>>

-- 
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/fb987200-6678-443f-a0ab-884b5f77c324n%40googlegroups.com.


[go-nuts] Re: Is overwriting contents of pointer field the expected behavior of json.Unmarshal?

2022-08-22 Thread Tamás Gulácsi
"To unmarshal a JSON array into a slice, Unmarshal resets the slice length 
to zero and then appends each element to the slice."

And you gave "" to Unmarshal twice. So it zeroed the length, and 
appended the second time,
effectively overwriting the first (and only) element.
This is intended behaviour.

The problem is not this, but your use of newElems - although it's length is 
zeroed, the first element is still there, so Unmarshal uses it, and fills P,
instead of allocating a new *int.

If you zero out the element, it will allocate a new pointer, as you want:

https://go.dev/play/p/vgkbG0LZ2nr

Mateusz Wójcik a következőt írta (2022. augusztus 23., kedd, 1:01:01 UTC+2):

> The test code below demonstrates a json.Unmarshal behavior that I find 
> unexpected. The code unmarshals arrays of objects with pointers fields. All 
> unmarshaled objects end up sharing the same pointer value, effectively 
> overwriting the contents of the pointer.
>
> package unmarshall
>
> import (
> "encoding/json"
> "fmt"
> "testing"
>
> "github.com/stretchr/testify/assert"
> )
>
> func TestUnmarshal(t *testing.T) {
> type Elem struct {
> V int
> P *int
> }
>
> elems := []Elem(nil)
> newElems := []Elem(nil)
>
> json.Unmarshal([]byte(`[{"V":10, "P":1}]`), )
> elems = append(elems, newElems...)
>
> json.Unmarshal([]byte(`[{"V":20, "P":2}]`), )
> elems = append(elems, newElems...)
>
> assert.Equal(t, 10, elems[0].V)
> assert.Equal(t, 1, *elems[0].P)
>
> assert.Equal(t, 20, elems[1].V)
> assert.Equal(t, 2, *elems[1].P)
>
> assert.NotEqual(t, elems[0].P, elems[1].P)
> }
>
> ​
> I find the behavior unexpected because the documentation of json.Unmarshal 
> states:
>
> // To unmarshal a JSON array into a slice, Unmarshal resets the slice length
> // to zero and then appends each element to the slice.
>
> ​
> However, reseting the slice length to zero and appending elements to the 
> slice results in different behavior:
>
> func TestAppend(t *testing.T) {
>type Elem struct {
>   V int
>   P *int
>}
>
>elems := []Elem(nil)
>newElems := []Elem(nil)
>
>one, two := 1, 2
>
>newElems = append(newElems[:0], Elem{V: 10, P: })
>elems = append(elems, newElems...)
>
>newElems = append(newElems[:0], Elem{V: 20, P: })
>elems = append(elems, newElems...)
>
>assert.Equal(t, 10, elems[0].V)
>assert.Equal(t, 1, *elems[0].P)
>
>assert.Equal(t, 20, elems[1].V)
>assert.Equal(t, 2, *elems[1].P)
>
>assert.NotEqual(t, elems[0].P, elems[1].P)
> }
>
> ​
> Are my expectations of the above behavior incorrect?
>

-- 
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/a7613b82-a134-445e-94b3-3cd48471f576n%40googlegroups.com.


[go-nuts] Re: gouse — toggle ‘declared but not used’ errors

2022-08-08 Thread Tamás Gulácsi
This is horrible.

The 'declared but not used' error saved me hundreds of times, 
and for experimenting, adding a "_ = notUsed" or hide the whole part behind 
an "if false" is not a burden.

george...@gmail.com a következőt írta (2022. augusztus 6., szombat, 
16:26:33 UTC+2):

> Hi everyone!
>
> I created a CLI tool for toggling ‘declared but not used’ errors by using 
> idiomatic ‘_ = notUsedVar’ and leaving a TODO comment to make sure you 
> haven’t forgotten to remove fake usages. Serves best as back end for some 
> wrapper in form of extension for an IDE or an editor. Easily integratable 
> into Vim. There is also VS Code extension 
> . Will 
> be glad if someone will make a wrapper for GoLand.
>
> Example:
> var (
> notUsed0 = false
> used0bool
> )
> notUsed1, used1 := "", ""
> _, _ = used0, used1
>
> turns into
> var (
> notUsed0 = false; _ = notUsed0 /* TODO: gouse */
> used0bool
> )
> notUsed1, used1 := "", ""; _ = notUsed1 /* TODO: gouse */
> _, _ = used0, used1
>
> On the next call, gouse will return everything back to the initial state.
>

-- 
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/0bc57678-c86a-4769-8135-d4ccf6c1c0ean%40googlegroups.com.


[go-nuts] Re: goroutine benchmark results interpretation for anonymous func?

2022-06-12 Thread Tamás Gulácsi
ch <- bytes.Contains(b.Bytes()[start:end], find)
   select {
   case <-quit:
quit <- "bye"
 return
   }

Don't you want a "default:" case in there? This way all your goroutines are 
kept alive and waiting for that quit - which only ONE goroutine will get!
Use close(quit) - that will signal all goroutines!

BTW your bytes.Contains won't break mid-execution, so it either executes, 
or it haven't even started yet on "quit".
You have to break the problem to smaller chunks and loop on it, checking 
the quit channel on each iteration.

Or accept that this few hundred MBs is not big, and forget all the 
complexity, just bytes.Contains each part (/core) and write the result into 
a make([]bool, core), at the right index,
and at last iterate over this result slice and check whether any found sth.
You'll still need a WaitGroup for waiting all goroutines.

Const V a következőt írta (2022. június 13., hétfő, 1:55:11 UTC+2):

> The way I'm using is "b" is a large buffer - hundreds of MB.
> I want to stop processing after the string is found using "quit".
>
> for i := 0; i < cores; i++ {
>  go func(start, end, i int, quit chan string) {
>ch <- bytes.Contains(b.Bytes()[start:end], find)
>select {
>case <-quit:
> quit <- "bye"
>  return
>}
>  }(start, end, i, quit)
> }
> for i := 0; i < cores; i++ {
> if <-ch { // the result from bytes.Contains is true so I want to 
> stop processing the other routines.
> quit <- "quit"
>  }
>  }
>
> the whole point was the question is why if I use 
> BytesContainsCh1(b.Bytes(), start, end, find, ch)
> the processing is faster: 4.99s 
> rather using 
> ch <- bytes.Contains(b.Bytes()[start:end], find)
> 6.47s 
>
> which takes longer.
> The logic says it should be otherwise because BytesContainsCh1 is a 
> function call and it should be slower.
> On Sunday, June 12, 2022 at 2:11:57 PM UTC-7 Brian Candler wrote:
>
>> No: I'm suggesting exactly what I wrote.  Starting a goroutine looks like 
>> this:
>>
>> go ()
>>
>> It doesn't have to be an anonymous function, it can be a "real" 
>> function.  Hence this is perfectly valid:
>>
>> go BytesContainsCh1(b.Bytes(), start, end, find, ch)
>>
>> On Sunday, 12 June 2022 at 18:17:23 UTC+2 Const V wrote:
>>
>>> I already have a go routine on the anonymous function:
>>> go func(start, end, i int, quit chan string) {
>>>
>>> You are suggesting doing this?
>>> go func(start, end, i int, quit chan string) {
>>>   go BytesContainsCh1(b.Bytes(), start, end, find, ch)
>>>}(start, end, i, quit)
>>>
>>> On Sunday, June 12, 2022 at 2:54:51 AM UTC-7 Brian Candler wrote:
>>>
 On Sunday, 12 June 2022 at 09:16:30 UTC+1 Const V wrote:

>   go func(start, end, i int, quit chan string) {
>   BytesContainsCh1(b.Bytes(), start, end, find, ch)
>}(start, end, i, quit)
>

 I note that this could be further simplified to:

 go BytesContainsCh1(b.Bytes(), start, end, find, ch)
  
 Maybe the compiler does this optimisation automatically.  Does it make 
 any difference to your timings?

 If you want to understand the difference you might need to look at the 
 assembly language generated. See what happens with the number of stack 
 frames allocated, whether the unused argument 'i' is elided in one of the 
 cases, and so on.

>

-- 
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/21c9ae98-3136-4701-bca9-67b39c13bdb4n%40googlegroups.com.


[go-nuts] Re: Best coding practice for resiliient client-server communications

2022-05-25 Thread Tamás Gulácsi
I bet on https://pkg.go.dev/github.com/rogpeppe/retry - it allows a simple 

for iter := strategy.Start(); iter.Next(ctx.Done()); {
  if err := todo(ctx); err == nil {
break
  } else if permanent(err) {
break
  }
}

portt...@gmail.com a következőt írta (2022. május 25., szerda, 16:02:16 
UTC+2):

> This was an interesting read: 
>
> "Timeouts, retries, and backoff with jitter"
>
> https://aws.amazon.com/builders-library/timeouts-retries-and-backoff-with-jitter/
>
> I wonder what is a good practice in Go code to retry/reconnect/recover but 
> not too aggressively, when connections fail or are stalling or choppy? (Not 
> really AWS specific...) 
>
>
>

-- 
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/119cbaba-d3b7-4cc0-b1b5-7d86c71bcf7bn%40googlegroups.com.


[go-nuts] Re: Which is the most efficient way to read STDIN lines 100s of MB long and tens of MB info is passed to it?

2022-05-08 Thread Tamás Gulácsi
If that "100s of MB" is acceptable to be in memory, then bufio.Scanner with 
properly sized scanner.Buffer is the easiest and battle tested solution.

If not, then you have to reimplement the same, with a temp file as a 
buffer: read input, store in file, seeking to the start on each '\n', 
copying the file to STDOUT when "test" is found.
Not too hard, but have a few edge cases.
Const V a következőt írta (2022. május 7., szombat, 22:40:58 UTC+2):

> I need to write a program that reads STDIN and should output every line 
> that contains a search word "test" to STDOUT. 
>
> How I can test that considering the problem is a line can be 100s of MB 
> long (\n is line end) and tens of MB info is passed to it.
>

-- 
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/0a97a330-cc0a-4919-b05e-64a898ab8392n%40googlegroups.com.


[go-nuts] Re: How to format hour in 24h format without leading 0 ?

2022-04-25 Thread Tamás Gulácsi
strings.Replace(t.Format(time.RFC3339), "T0", "T", 1)
?

christoph...@gmail.com a következőt írta (2022. április 25., hétfő, 
18:10:45 UTC+2):

> I need to format a time stamp hours in 24h format but without leading 0. 
> This means 7 -> "7" and 17 -> "17".
>
> For 24h values, the only formatting key value provided and documented is 
> 15. But this produces "7" -> "07" and 17 -> "17" which is not what I need.
>
> According to  https://gosamples.dev/date-time-format-cheatsheet/, a 
> formatting key word for this format seam to be missing. 
>
> Note by the way that the formatting key value numbering is easy to 
> remember for Americans only. Every time I need to format a time value I 
> have to look it up with google, or the cheat sheet referenced above.
>

-- 
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/2075ef73-19fd-4ad4-b4a6-0910bf348cb6n%40googlegroups.com.


[go-nuts] ZipFS using testing/fstest#MapFS

2022-03-24 Thread Tamás Gulácsi
Hi,

I'd like to thank The Google Authors for 
https://pkg.go.dev/testing/fstest#MapFS - it just needed a very little 
tweaking to serve as a zip-backed fs.FS: 
https://pkg.go.dev/github.com/tgulacsi/go/zipfs.

The filenames, (missing) directory names in then zip.Reader.File slice gave 
me quite substantial bugs, so after using testing/fstest and staring at the 
bugs reported, it hit me:
fstest.MapFS is _almost_ the same as what I need.

Looking into the implementation, that filename/path fiddling, the 
synthetization of missing directories is far from simple, so the easiest 
was to just copy it as-is.

Is the included comment enough, and can it be used under Apache-2.0 
license, or should I keep the BSD license for this code?
https://github.com/tgulacsi/go/blob/v0.19.7/zipfs/zipfs.go#L64-L70


Thanks,
Tamás Gulácsi

-- 
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/69206751-5829-411c-baa7-78dc59fce930n%40googlegroups.com.


[go-nuts] Re: Pod memory keeps on increasing and restart with error OOMKilled

2022-03-10 Thread Tamás Gulácsi
gopkg.in/confluentinc/confluent-kafka-go.v1/kafka._Cfunc_GoBytes

says it uses cgo, hiding it's memory usage from Go. I bet that 900MiB of 
memory is there...


Rakesh K R a következőt írta (2022. március 10., csütörtök, 7:26:57 UTC+1):

> HI,
> I have a micro service application deployed on kubernetes cluster(with 1gb 
> of pod memory limit). This app receive continuous messages(500 message per 
> second) from producer app over kafka interface(these messages are encoded 
> in protobuf format.)
>
> *Basic application flow:*
> 1. Get the message one by one from kafka
> 2. unmarshal proto message
> 3. apply business logic
> 4. write the message to redis cache(in []byte format)
>
> When pod starts memory will be around 50mb and memory starts increasing as 
> traffic flows into the application. It is never released back to OS. As a 
> result pod restarts with error code *OOMKilled*.
> I have integrated grafana to see memory usage like RSS, heap, stack.
> During this traffic flow, in-use heap size is 80mb, idle heap is 80mb 
> where as process resident memory is at 800-1000MB. Stopping the traffic 
> completely for hours did not help and RSS continue to remain in 1000mb.
> Tried to analyze this with pprof and it reports only 80mb are in in-use 
> section. So I am wondering where these remaining 800-1000mb of pods memory 
> went. Also application allocates memory like slices/maps/strings to perform 
> business logic(see alloc_space pprof output below)
>
> I tried couple of experiments:
> 1. Calling FreeOsMemory() in the app but that did not help
> 2. invoking my app with GODEBUG=madvdontneed=1 my_app_executable and did 
> not help
> 3. Leaving the application for 5-6hrs without any traffic to see whether 
> memory comes down. It did not help
> 4. pprof shows only 80mb of heap in use
> 5. Tried upgrading golang version from 1.13 to 1.16 as there were some 
> improvements in runtime. It did not help
>
> pprof output for *alloc_space*:
>
> (pprof) top20
> Showing nodes accounting for 481.98GB, 91.57% of 526.37GB total
> Dropped 566 nodes (cum <= 2.63GB)
> Showing top 20 nodes out of 114
>   flat  flat%   sum%cum   cum%
>78.89GB 14.99% 14.99%78.89GB 14.99%  
> github.com/go-redis/redis/v7/internal/proto.(*Reader).readStringReply
>67.01GB 12.73% 27.72%   285.33GB 54.21% 
>  airgroup/internal/wrapper/agrediswrapper.GetAllConfigurationForGroups
>58.75GB 11.16% 38.88%58.75GB 11.16%  
> google.golang.org/protobuf/internal/impl.(*MessageInfo).MessageOf
>52.26GB  9.93% 48.81%52.26GB  9.93%  reflect.unsafe_NewArray
>45.78GB  8.70% 57.50%46.38GB  8.81% 
>  encoding/json.(*decodeState).literalStore
>36.98GB  7.02% 64.53%36.98GB  7.02%  reflect.New
>28.20GB  5.36% 69.89%28.20GB  5.36%  
> gopkg.in/confluentinc/confluent-kafka-go.v1/kafka._Cfunc_GoBytes
>25.60GB  4.86% 74.75%63.62GB 12.09%  
> google.golang.org/protobuf/proto.MarshalOptions.marshal
>12.79GB  2.43% 77.18%   165.56GB 31.45% 
>  encoding/json.(*decodeState).object
>12.73GB  2.42% 79.60%12.73GB  2.42%  reflect.mapassign
>11.05GB  2.10% 81.70%63.31GB 12.03%  reflect.MakeSlice
>10.06GB  1.91% 83.61%12.36GB  2.35% 
>  filterServersForDestinationDevicesAndSendToDistributionChan
> 6.92GB  1.32% 84.92%   309.45GB 58.79% 
>  groupAndSendToConfigPolicyChannel
> 6.79GB  1.29% 86.21%48.85GB  9.28% 
>  publishInternalMsgToDistributionService
> 6.79GB  1.29% 87.50%   174.81GB 33.21%  encoding/json.Unmarshal
> 6.14GB  1.17% 88.67% 6.14GB  1.17%  
> google.golang.org/protobuf/internal/impl.consumeBytes
> 4.64GB  0.88% 89.55%14.39GB  2.73% 
>  GetAllDevDataFromGlobalDevDataDb
> 4.11GB  0.78% 90.33%18.47GB  3.51%  GetAllServersFromServerRecordDb
> 3.27GB  0.62% 90.95% 3.27GB  0.62%  net.HardwareAddr.String
> 3.23GB  0.61% 91.57% 3.23GB  0.61%  reflect.makemap
> (pprof)
>
>
> Need experts help in analyzing this issue.
>
> Thanks in advance!!
>

-- 
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/c578632b-008b-4b42-883c-615bd2f9244dn%40googlegroups.com.


[go-nuts] Re: Download a zip file from a URL

2022-03-10 Thread Tamás Gulácsi
You miss the error returned by out.Close(). So, finish DownloadFile with 
"return out.Close()"
And os.Create will truncate the file, no need to Remove it - though if you 
want to remove, just "_ = os.Remove(filepath) "- don't check the error.


Gaurav a következőt írta (2022. március 10., csütörtök, 6:54:30 UTC+1):

> I am trying to download a zip file using a simple http Get. This program 
> downloads the file but the downloaded file is corrupted.
>
> package main
> import (
> "fmt"
> "io"
> "net/http"
> "os"
> )
>
> func DownloadFile(url string) error {
> resp, err := http.Get(url)
> if err != nil {
> return err
> }
> defer resp.Body.Close()
>
> filepath := "test.zip"
>
> _, err = os.Stat(filepath)
> if err == nil {
> err := os.Remove(filepath)
> if err != nil {
> return err
> }
> }
>
> out, err := os.Create(filepath)
> if err != nil {
> return err
> }
> defer out.Close()
>
> _, err = io.Copy(out, resp.Body)
> if err != nil {
> return err
> }
>
> return nil
> }
>
> func main() {
> err := DownloadFile("
> https://store1.gofile.io/download/78f1898f-2b02-465a-a39c-4cf7e35822a2/test.zip
> ")
> if err != nil {
> fmt.Println(err)
> }
> }
>
> What am I missing here? Regards
> Gaurav
>
>

-- 
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/c3d2ea0a-5fb3-4791-8715-07978a3dd27fn%40googlegroups.com.


[go-nuts] Re: how to solve the go.mod conflict when 2 sub-modules point to break version of a common module

2022-03-07 Thread Tamás Gulácsi
Sorry to say, but *go.opentelemetry.io/otel 
* is a dumpster fire of API breakage and 
flux.
I don't know other solution than modify a or b to use the same version of 
otel.

ian.zh...@gmail.com a következőt írta (2022. március 7., hétfő, 17:49:17 
UTC+1):

> Hi team,
>
> I'm working on a new package, *demo*, which has a dependency on *a* and 
> *b*.
>
> Both *a* and *b* are pointing to `go.opentelemetry.io/otel` 
> 
>
> *a* points to *go.opentelemetry.io/otel * 
> v0.20.0
> *b* points to *go.opentelemetry.io/otel * 
> v0.25.0
>
> However, the *go.opentelemetry.io/otel * 
> introduced break changes between these 2 versions.
> At *v0.25.0*, it dropped some functions that exist in *v0.20.0* and 
> *v0.25.0* has some new functions.
>
> In my *demo*, the *go mod tidy* would point to v0.20.0, in this way, it 
> breaks the dependency of *b.*
>
> I tried to modify the *go.mod *of *demo* in order to find a common 
> version between *a* and *b*, but I can't 
> find such. 
>
> I wonder if there's a way to let *go mod* to allow specific module 
> versions for *a* and *b. *If not, what's other 
> possible ways to solve this issue?
>
>
> Looking forward to your reply.
> 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/6e7d76e0-89f1-4af9-80cf-11de8dda37e1n%40googlegroups.com.


Re: [go-nuts] Is there a way to syncronise map reads and writes?

2022-02-22 Thread Tamás Gulácsi
Use a slice instead of a map ?

Jason E. Aten a következőt írta (2022. február 23., szerda, 7:10:04 UTC+1):

> Unfortunately, that's not how Go maps work. You'll still get races unless 
> you synchronize even "read-only" maps.
>
> On Tuesday, February 22, 2022 at 11:59:37 PM UTC-6 ren...@ix.netcom.com 
> wrote:
>
>> The top level map locks doesn’t matter - it is write once at init and 
>> read only after. 
>>
>> On Feb 22, 2022, at 11:51 PM, Jason E. Aten  wrote:
>>
>> You have not synchronized access to the top level mapLocks map itself.  
>> Thus you will get races. You need to have a mutex that you lock before you 
>> access mapLocks; not just the maps that are inside it.
>>
>>
>> I would also recommend being a little object oriented about this design, 
>> putting each map inside its own struct, and make a set of accessor methods 
>> that Lock() and defer Unlock() on a mutex that protects the maps inside.  
>> Read code like this for an idea of what I mean. 
>> https://github.com/glycerine/atomicmap/blob/master/amap.go
>>
>> On Tuesday, February 22, 2022 at 9:55:04 PM UTC-6 ren...@ix.netcom.com 
>> wrote:
>>
>>> Something else is wrong - because marketMaps is read-only after init… so 
>>> unless you have some other code - that is not the map causing the panic.
>>>
>>> My guess is because you are returning the map from ReadMaps (or RWMaps) 
>>> that you are using THAT map by multiple threads outside the lock (the map 
>>> is a reference not a copy) and that is causing the panic.
>>>
>>> On Feb 22, 2022, at 9:39 PM, Zhaoxun Yan  wrote:
>>>
>>> Hi guys!
>>> I know this is quite challenging, but it makes sense in io-heavy 
>>> applications.
>>>
>>> I need to test the responsiveness of different financial future 
>>> quotation sources. They return the quotations spontaneously, and my program 
>>> respond to each one of the CGO call backs from the quotation library and 
>>> save the current prices. Meanwhile, a timer ensures to check the current 
>>> quotations of each available sources. And obviously, it raised up a panic 
>>> due to synchronization of maps on the call of ReadMaps function. 
>>> Unfortunately this came up occasionally and `go build -race` cannot raise 
>>> the problem.
>>>
>>> Here is a piece of the code, only the read/write part:
>>>
>>>
>>> --
>>>
>>> // Please Ignore SyChan to alert the timer that all available sources 
>>> are collected 
>>> var SyChan chan int = make(chan int, 3)
>>>
>>> // Make up a map of 5 mutex locks and a map of 5 data structs, indexed 
>>> by 1-5
>>> var marketMaps = make(map[int]map[string]Market)
>>> var mapLocks = make(map[int]*sync.Mutex)
>>>
>>> // quotation data
>>> type Market struct {
>>> Price float64 `json:"price"`
>>> Timestamp string  `json:"timestamp"`
>>> }
>>>
>>> func init() {
>>> for i := 1; i <= 5; i++ {
>>> mapLocks[i] = new(sync.Mutex)
>>> marketMaps[i] = make(map[string]Market)
>>> }
>>> }
>>>
>>> //Make sure that for each source, R/W has no race, only took place as 
>>> acquiring the particular Mutex inside the map of Mutex.
>>> func RWMaps(targetnum int, purpose, future_id string, market Market) 
>>> map[string]Market {
>>> 
>>> mapLocks[targetnum].Lock()
>>> defer mapLocks[targetnum].Unlock()
>>>
>>> if purpose == "update" {//The original Write part
>>> marketMaps[targetnum][future_id] = market
>>>return nil
>>> } else { //The read part, has been extracted to ReadMaps
>>> SyChan <- 1
>>> return marketMaps[targetnum]
>>> }
>>> }
>>>
>>> //Here is why I use map: not all 5 sources must be available, some may 
>>> have connection failure and would be marked as false in Usable[i] , i being 
>>> its source No.
>>> func ReadMaps(targetnum, checkTime int) map[string]Market {
>>> mapLocks[targetnum].Lock()
>>> defer mapLocks[targetnum].Unlock()
>>> if Usable[targetnum] {
>>> fmt.Printf("%d-th time to read source %d \n", checkTime, 
>>> targetnum)
>>> }
>>> SyChan <- 1
>>> return marketMaps[targetnum]
>>> }
>>>
>>>
>>> --
>>>
>>> My problem is :
>>>
>>> I still want to keep the map structure, rather than naming mutex1, 
>>> mutex2, mutex3,... , marketmsg1, marketmsg2,  And obviously if the map 
>>> prohibits reading or writing spontaneously, the writing by each usable 
>>> sources is not fair - They must line up as one queue (like using one Mutex 
>>> for all instead) hence the checking of quotation snap on a time-spot is 
>>> defected.  I have also checked the sync.Map and it seems to allow 
>>> spontaneous reading but still prohibits spontaneous writing.
>>>
>>> My instinct is to make map on the pointer of structs. On that 

[go-nuts] Re: Running golangci-lint run for various different files

2022-01-27 Thread Tamás Gulácsi
Just as with other tools, golangci-lint run runs on packages, not 
individual files:

golangci-lint run ./app ./utils/db

Beginner a következőt írta (2022. január 26., szerda, 18:08:28 UTC+1):

> Hey when i run golangci-lint run app/main.go utils/db/db.go i get an 
> error stating `named files must all be in one directory golang` why is 
> that ?

-- 
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/75f61c03-63bc-48c2-990f-13268d5d959cn%40googlegroups.com.


[go-nuts] Re: Drawing millions of images on a bigger canvas

2022-01-22 Thread Tamás Gulácsi
A large canvas needs large amount of memory.
32x35x4 byte is about 4.4Kib, so one million is 4272Mib.
Just as your MemProfile says.

Either use some image format that can be written in chunks (AFAIK PNG can 
do this, but that's quite low-level),
or mmap the region of the pixels, or leave it to tho OS (swapping).

kryptic...@gmail.com a következőt írta (2022. január 23., vasárnap, 0:02:21 
UTC+1):

> Hi, what would be the correct way to composite millions of images on a 
> larger canvas?
> I am trying to composite a lot of 32x35 pngs to a larger canvas but the 
> method I am using, draw.Draw() seems to be too hungry for resources choking 
> the GC again and again.
>
> CPUProfile and MEMProfile added below. 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/16af218f-3bf9-43aa-84fd-ed888a1d6ba8n%40googlegroups.com.


Re: [go-nuts] No time.Duration#UnmarshalText; is there a good reason?

2022-01-19 Thread Tamás Gulácsi
time.Duration.String() already does the pretty printing: 
https://pkg.go.dev/time@master#Duration.String
time.ParseDuration is the parser which could be used in UnmarshalText.

rog a következőt írta (2022. január 19., szerda, 12:55:49 UTC+1):

> On Wed, 19 Jan 2022 at 04:19, Ian Lance Taylor  wrote:
>
>> On Mon, Jan 17, 2022 at 9:53 PM Corin Lawson  wrote:
>> >
>> > It seems obvious (to me) that the encoding.TextUnmarshaler interface 
>> could be implemented for time.Duration (it is implemented for time.Time, 
>> afterall).
>> >
>> > The fact that it is not gives me pause... is there a good reason that 
>> the stdlib has not done this?  What issues am I facing if I do this: 
>> https://go.dev/play/p/nHBfS7TJQtJ
>> >
>> > ```
>> > // UnmarshalText implements the encoding.TextUnmarshaler interface.
>> > func (d *Duration) UnmarshalText(data []byte) error {
>> > val, err := time.ParseDuration(string(data))
>> > *d = Duration(val)
>> > return err
>> > }
>> > ```
>>
>> A time.Duration is just an integer.  The standard text marshaling and
>> unmarshaling work fine.
>>
>
> They do work fine in the technical sense, but marshalling a 1s duration as 
> 10 doesn't make for a particularly readable specification of a 
> duration when found in configuration (it's so easy to misread the number of 
> digits). I've often wrapped a time.Duration in a type that implements 
> marshaling and unmarshaling so it's possible to write 1s, 500ms, etc.
>  
> Unfortunately I don't believe that's possible to add retrospectively 
> because marshaling using Duration.String would break any existing users 
> that expect a number.
>
>   cheers,
> rog.
>
>
>> 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...@googlegroups.com.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/golang-nuts/CAOyqgcUbSaTJ15zT7ksQmDMaf2oq%2B0oY5uN-kzzKHXa-6JjnJw%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/ffdb51b7-d73a-4e2f-bf51-a816b2c81d85n%40googlegroups.com.


Re: [go-nuts] Re: Wrong output for (*http.Request).Write with custom io.ReadCloser body

2022-01-14 Thread Tamás Gulácsi
Why not set Request.ContentLength beforehand (you know it)?

dmo...@synack.com a következőt írta (2022. január 14., péntek, 18:56:57 
UTC+1):

> Sorry to insist, but I think there's also a performance issue with the 
> current implementation. Given that the service I need to communicate to 
> requires me to send Content-Length header I am forced to read into memory 
> potentially large files that I want to send them, buffering them in one of 
> the three (undocumented!) *structs that are known 
> (*bytes.Buffer, *bytes.Reader or *strings.Reader) instead of being able to 
> just pass the *os.File. Thing is, I could analyze the size of each file, 
> break it down into parts that I can read into memory and make a request for 
> each part that the service would later join into a single file, but that 
> sounds like overkill and also sounds like a lot of work and overhead for 
> something that could be done with a simple io.Reader.
>
> I think that the easiest way to overcome this issue and at the same time 
> not break the promises made would be to do something like:
>
> func readerLength(body io.Reader) (int64, error) {
> if f, _ := body.(fs.File); f != nil {
> if i, err := f.Stat(); err == nil { // discard error and 
> try io.Seeker interface later (it's cheaper to stat instead of seeking)
> return i.Size(), nil
> }
> }
>
> if s, _ := body.(interface { // covers *bytes.Reader and other
> Size() int64
> }); s != nil {
> return s.Size(), nil
> }
>
> if l, _ := body.(interface { // covers all the three current 
> undocumented items: *bytes.Buffer, *bytes.Reader and *strings.Reader
> Len() int
> }); l != nil {
> return int64(l.Len()), nil
> }
>
> if s, _ := body.(io.Seeker); s != nil { // covers a lot of other 
> cases, like multipart.File, errors statting *os.File, etc.
> cur, err := s.Seek(0, io.SeekCurrent)
> if err != nil {
> return -1, fmt.Errorf("error checking current 
> position: %w", err)
> }
>
> end, err := s.Seek(0, io.SeekEnd)
> if err != nil {
> return -1, fmt.Errorf("error seeking end position: 
> %w", err)
> }
>
> _, err = s.Seek(cur, io.SeekStart)
> if err != nil {
> return -1, fmt.Errorf("error going back to initial 
> position: %w", err)
> }
>
> return end - cur, nil
> }
>
> return -1, errors.New("unknown body, don't send the Content-Length 
> header")
> }
>
>
>
> On Friday, September 17, 2021 at 2:23:50 PM UTC-3 Diego Molina wrote:
>
>> Ok, that makes total sense. I'm now using `req.TransferEncoding = 
>> []string{"identity"}` and this behaviour is suppressed, but of course I 
>> still don't get the Content-Length, which is fair.
>>
>> Thanks all!
>>
>> On Fri, Sep 17, 2021 at 2:09 PM Brian Candler  wrote:
>>
>>> All chunks must be prefixed by a chunk length - even if that length is 
>>> zero.
>>>
>>> On Friday, 17 September 2021 at 16:53:07 UTC+1 dmo...@synack.com wrote:
>>>
 Oh, thanks for clarifying that. But still, even if transfer encoding 
 will be chunked, I don't see why it would make up a body of "0\r\n\r\n" if 
 the nop body wouldn't give away any bytes at all.

 On Friday, September 17, 2021 at 7:56:21 AM UTC-3 seank...@gmail.com 
 wrote:

> This was an intentional change in 1.8 
> https://github.com/golang/go/issues/20257#issuecomment-299509391
>
> On Friday, September 17, 2021 at 6:45:13 AM UTC+2 dmo...@synack.com 
> wrote:
>
>> Hi, when using a custom io.ReadCloser nop as body with method POST, 
>> PUT, PATCH, TRACE or custom then (*http.Request).Write outputs a body of 
>> the form "0\r\n\r\n" (without the quotes). Proof-of-concept: 
>> https://play.golang.org/p/Rg2cZ0wihdd
>>
>> Besides the fix, I think it would be useful to have body checked if 
>> it satisfies interface{ Len() int } or something similar (this would 
>> simplify code too by removing several type assertions, e.g., 
>> isKnownInMemoryReader func in net/http/trans...@go1.17.1) so that we can 
>> avoid chunked transfer encoding.
>>
>> This email may contain material that is confidential for the sole use 
>> of the intended recipient(s).  Any review, reliance or distribution or 
>> disclosure by others without express permission is strictly prohibited.  
>> If 
>> you are not the intended recipient, please contact the sender and delete 
>> all copies of this message.
>>
> -- 
>>> You received this message because you are subscribed to a topic in the 
>>> Google Groups "golang-nuts" group.
>>> To unsubscribe from this topic, visit 
>>> 

[go-nuts] Re: json: cannot unmarshal object into Go value of type []main.ConnectwiseTicket

2021-12-08 Thread Tamás Gulácsi
Why on earth does everybody paste screenshots about TEXTs???

Please copy-paste simple text as simple text!
Color does not convey information, only hides.
Your code is readable, but the error message _is_not_.

linfr...@gmail.com a következőt írta (2021. december 8., szerda, 18:21:04 
UTC+1):

> So I am running my .go file to update things but I keep getting this 
> error. Not completly sure why it could be happening. I debuged it and it 
> seems to be happening here.[image: Capture4.PNG]
> [image: Capture3.PNG]
>

-- 
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/f13e20f8-5add-4353-8a50-afba3329549bn%40googlegroups.com.


[go-nuts] Re: How to setup a local directory as a go proxy

2021-11-02 Thread Tamás Gulácsi
What should that server do?
I'd check out caddy (caddyserver.com) first.

trb...@gmail.com a következőt írta (2021. november 2., kedd, 18:18:16 
UTC+1):

> I am trying to setup a go proxy based in/on a local directory.
>
> I can setup and run a number of different go proxies, but I am not sure 
> what the directory/folder structure needs to be.
>
> Has anyone done this?
>
> Is it possible to use a file based proxy without running some sort of 
> proxy server?
>
> Thanks
> Terry
>

-- 
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/7b984f68-0a4f-48da-aaee-8a1beaffe529n%40googlegroups.com.


[go-nuts] Re: Trouble with pgx package

2021-10-02 Thread Tamás Gulácsi
Another problem is that INSERT is not a query. Use QueryContext for SELECT 
statements, and ExecContext for everything else.

muhorto...@gmail.com a következőt írta (2021. október 2., szombat, 12:52:44 
UTC+2):

> Just started making my first web, I don't quite understand the Query Row 
> function. An error is returned, I process it. What is the error?
> func save(w http.ResponseWriter, r *http.Request) {
> login := r.FormValue("login")
> password := r.FormValue("password")
> if login == "" || password == "" {
> fmt.Fprint(w, "Не все данные введены")
> }
> conn, err := pgx.Connect(context.Background(), connStr)
> if err != nil {
> fmt.Fprintf(os.Stderr, "Unable to connect to database: %v\n", err)
> os.Exit(1)
> }
>
> err := conn.QueryRow(context.Background(), "INSERT INTO users (login, 
> password) VALUES ($1, $2)", login, password)
> if err != nil {
> return err
> }
> defer conn.Close(context.Background())
> http.Redirect(w, r, "/", http.StatusSeeOther)
> }
>

-- 
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/91437114-d608-4e4b-91cc-6846c61e64bcn%40googlegroups.com.


Re: [go-nuts] What is the total max size of embed content?

2021-09-22 Thread Tamás Gulácsi
Go back to the venerable SFX zip archives: Append the file as a 
(uncompressed?) ZIP file to the Go binary.
That binary can then open itself as a ZIP and read/use the database, and 
every other program will see it as a zip file.

Or just simply append the database and its uint64 size to the go binary.
Then it can open/mmap the exact bytes needed.

glen@gmail.com a következőt írta (2021. szeptember 21., kedd, 21:41:42 
UTC+2):

> Hello Ian,
>
> Yes, I think it is time I explain the 'why' of my inquiries into this. :-)
>
> My use case is this: Go, with its fast startup, pretty fast execution and 
> pretty small memory footprint, as well as it's ability to deploy as a 
> single binary, makes it a great language for cloud function-as-a-service 
> (FAAS). 
>
> My specific FAAS use case is for static, read-only databases: I am looking 
> at embedding modest sized (few GB to 10s of GB) read-only databases in the 
> Go binary. 
>
> This makes it possible to avoid the cost/complication of either using a 
> cloud db, or storing the db in (in the case of AWS) on a file system like 
> EFS (NFS), which the lambda has to mount. The databases are only updated 
> every couple of months / yearly.
> This is perhaps rather an obscure use case, but one that I think a number 
> of people would want to take advantage of.
>
> >Note that such files are going to take a long time to create and will be 
> unwieldy to use.
> Agreed. On my older desktop (Dell 7010 Kubuntu 20.10 4core i5 16GM) it 
> takes 45s to compile a trivial Go program that embeds three 500GB files.
>
> Actually, this is no different from those who want the simplicity and cost 
> savings of serving an entire static web site from embedded files. The 
> primary difference is the scale.
>
> Thanks,
> Glen
>
>
> On Tuesday, September 21, 2021 at 1:28:12 PM UTC-4 Ian Lance Taylor wrote:
>
>> On Tue, Sep 21, 2021 at 6:23 AM Glen Newton  wrote: 
>> > 
>> > Looking at https://groups.google.com/g/golang-codereviews/c/xkHLQHidF5s 
>> and https://github.com/golang/go/issues/9862 and the code to which they 
>> refer, it seems to me that the limit is 2GB independent of platform (is 
>> this true?), as the linker is limited to 2e9. 
>> > Again, should have done more of my homework! :-) 
>> > 
>> > 
>> https://github.com/golang/go/blob/master/src/cmd/internal/obj/objfile.go#L305
>>  
>> > 
>> > // cutoff is the maximum data section size permitted by the linker 
>> > // (see issue #9862). const cutoff = 2e9 // 2 GB (or so; looks better 
>> in errors than 2^31) 
>> > const cutoff = 2e9 // 2 GB (or so; looks better in errors than 2^31) 
>> > 
>> > The comment indicates that this is a limit in the linker; is this a 
>> limit in the elf format? If No, could the linker et al be modified to 
>> accept larger static data? 
>>
>> You're right: it does look like cmd/link imposes a 2G total limit. 
>> This is not a limitation of the 64-bit ELF format. It should be 
>> possible to make it larger. 
>>
>> Note that such files are going to take a long time to create and will 
>> be unwieldy to use. While it should be possible to increase the size, 
>> I would not be surprised if you hit other limits fairly quickly. 
>>
>> 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/8c311d03-f9ee-4703-b9ce-1593ea3e227fn%40googlegroups.com.


[go-nuts] Re: setuid root

2021-09-20 Thread Tamás Gulácsi
chmod 4755 is not enough. Your binary must be owned by root, to run root - 
setuid means "run as owner".

Rich a következőt írta (2021. szeptember 20., hétfő, 19:54:33 UTC+2):

> Yes. I tried running an exec: cmd=exec.Command("whoami") and it came as my 
> user id not root.  But to set the permissions I'd run: 'chmod 4755 
> myapplication'
>
> On Monday, September 20, 2021 at 11:20:39 AM UTC-4 Tamás Gulácsi wrote:
>
>> You mean "chown root app; chmod 4755 app" ?
>>
>> Rich a következőt írta (2021. szeptember 20., hétfő, 16:57:38 UTC+2):
>>
>>> I am trying to create a go program so that I can peform an action that 
>>> is more complex than the example I have below. I can't give sudo right so 
>>> run the application due to some policy we have at work that certain groups 
>>> can only have read permissions. The company also have a policy that states 
>>> any new directory / file is set with restrictive permissions. What I wanted 
>>> to do is create a program that runs as root. (Like ping runs as root) but 
>>> it doesn't seem to work.
>>>
>>> package main
>>>
>>> import (
>>> "fmt"
>>> "os"
>>> "os/exec"
>>> )
>>>
>>> func main() {
>>>   cmd:=exec.Command("chmod","770", "/opt/app/mnt/mydirectory")
>>>   cmd.Stdout = os.Stdout
>>>   cmd.Stderr = os.Stderr
>>>   err:=cmd.Run()
>>>   if err != nil {
>>> fmt.Println("ERROR:", err)
>>>   }
>>> }
>>>
>>> When I compile, then do a chmod 4755, and run it. I get a permissions 
>>> denied. Looking for why this would be?
>>>
>>

-- 
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/f7b98090-5e32-44a9-983f-4b4cec52cb7dn%40googlegroups.com.


[go-nuts] Re: setuid root

2021-09-20 Thread Tamás Gulácsi
You mean "chown root app; chmod 4755 app" ?

Rich a következőt írta (2021. szeptember 20., hétfő, 16:57:38 UTC+2):

> I am trying to create a go program so that I can peform an action that is 
> more complex than the example I have below. I can't give sudo right so run 
> the application due to some policy we have at work that certain groups can 
> only have read permissions. The company also have a policy that states any 
> new directory / file is set with restrictive permissions. What I wanted to 
> do is create a program that runs as root. (Like ping runs as root) but it 
> doesn't seem to work.
>
> package main
>
> import (
> "fmt"
> "os"
> "os/exec"
> )
>
> func main() {
>   cmd:=exec.Command("chmod","770", "/opt/app/mnt/mydirectory")
>   cmd.Stdout = os.Stdout
>   cmd.Stderr = os.Stderr
>   err:=cmd.Run()
>   if err != nil {
> fmt.Println("ERROR:", err)
>   }
> }
>
> When I compile, then do a chmod 4755, and run it. I get a permissions 
> denied. Looking for why this would be?
>

-- 
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/df521cb8-432c-4dfc-93be-80197d9bb3e9n%40googlegroups.com.


[go-nuts] Re: How to capture the bytes of stdin

2021-08-18 Thread Tamás Gulácsi
You have to io.Copy(cmdStdin, os.Stdin) to use your program's stdin, and 
pipe it to the subprocess.

hyo...@gmail.com a következőt írta (2021. augusztus 18., szerda, 17:50:24 
UTC+2):

> The goal: I want to capture all the bytes of *cmd.Stdin* and process them 
> with this rot13 function: https://play.golang.org/p/VX2pwaIqhmT
>
> The story: I'm coding a small tool which will be cross compiled for both 
> win/ linux, so I'm trying to make it as simple as possible. This tool 
> connects to the server from which I can execute commands on the client.
>
> Since I had to do the same thing for cmd.Stdout, I used this:
>
> Where OBFprocessStream function is based on this one: 
> https://play.golang.org/p/j_TKZWuhGaK. Everything works fine here .
>
> ...
>
> conn, err := net.Dial(nObj.Type, nObj.TCPIndirizzo)
>
> ..
>
> cmd := exec.Command(/bin/sh, "-i") // please keep in mind that this is an 
> ***interactive*** 
>
> //***shell***, and not just a simple command   
>
> cmd.Stdin = conn
>
> cmdStdout, err := cmd.StdoutPipe() // works fine
>
> if err != nil {
>
> fmt.Fprintf(os.Stderr, "error creating shell stdout pipe: %s\n", err)
>
> }
>
> cmd.Stderr = conn
>
> err = cmd.Start()
>
> if err != nil {
>
> fmt.Fprintf(os.Stderr, "error starting shell: %s\n", err)
>
> }
>
> .
>
> err = OBFprocessStream(cmdStdout, conn) // works fine
>
> 
>
> So, I tried to replicate the same thing for cmd.Stdin:
>
> ...
>
> conn, err := net.Dial(nObj.Type, nObj.TCPIndirizzo)
>
> ..
>
> cmd := exec.Command(/bin/sh, "-i") 
>
> cmdStdin, err := cmd.StdinPipe() 
>
> if err != nil {
>
> fmt.Fprintf(os.Stderr, "error creating shell stdin pipe: %s\n", err)
>
> }
>
> cmdStdout, err := cmd.StdoutPipe()
>
> if err != nil {
>
> fmt.Fprintf(os.Stderr, "error creating shell stdout pipe: %s\n", err)
>
>
> }
>
> cmd.Stderr = conn
>
> err = cmd.Start()
>
> if err != nil {
>
> fmt.Fprintf(os.Stderr, "error starting shell: %s\n", err)
>
> }
>
> .
>
> err = INOBFprocessStream(cmdStdin, conn)
>
> .
>
> err = OBFprocessStream(cmdStdout, conn)
>
> 
>
> But.. cmdStdin is an Io.WriterCloser, and I don't really know what to do 
> to capture the bytes sEGIHOsegoihszrhoiò
>
> Can you please help me?
>

-- 
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/026e84bb-3230-494e-84f6-cff1a5ecf4a7n%40googlegroups.com.


Re: [go-nuts] sql.Row doubt

2021-08-14 Thread Tamás Gulácsi
It could, but what for? sql.Row is already a convenience wrapper for 
I-know-I-want-only-one-row,
so you know what kind of data are you retrieving, but you know it's only 
one row?

daniel...@omie.com.br a következőt írta (2021. augusztus 13., péntek, 
19:04:24 UTC+2):

> Yes i ever use Query() instead of QueryRow(). 
> My doubt is more about the API design.
> If exists *sql.Row with Scan() method why not implements Columns() ?
>
> On Thursday, August 5, 2021 at 3:43:44 PM UTC-3 eli...@gmail.com wrote:
>
>> In what case do you find the need to call Columns() on a Row? Generally 
>> if you have access to a Row, you also have access to a Rows, which does 
>> have a Columns() method.
>>
>> Eli
>>
>> On Thu, Aug 5, 2021 at 10:34 AM Daniel da Silva  wrote:
>>
>>> Hello guys!
>>>
>>> Why doesn't sql.Row implement the Columns() method? 
>>>
>>> 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...@googlegroups.com.
>>> To view this discussion on the web visit 
>>> https://groups.google.com/d/msgid/golang-nuts/1c521514-d267-456c-a66a-e56544965fd3n%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/21d5e098-edd8-45bf-ac56-070c55094ac4n%40googlegroups.com.


[go-nuts] Re: A peculiar sort problem

2021-07-27 Thread Tamás Gulácsi
First, sort all the bytes (0-255) with Go and .Net, and compare them.
For Unicode-unaware sorting, that'd be enough: create a mapping between the 
two tables, 
replace all the bytes in the Go's input before sort (or use a Less that 
does the translation),
thus replicating the .NET sort order.

amplep...@gmail.com a következőt írta (2021. július 27., kedd, 19:57:07 
UTC+2):

> Hi! 
>
> I am writing a tool that handles files and generates some sorted
> output. Since this tool is to be a replacement for part of
> another system (written in C#/.NET), the output must be a
> byte-exact duplicate.
>
> The existing system generates some checksums and filenames in a
> stable sorted order, like so (also pastebinned at
> https://dpaste.org/MLMv):
>
> ```
> addons/rhs_bmp.pbo 2D08606D9BCB43E37A44CDBCD753F663
> addons/rhs_bmp.pbo.rhsafrf.0.5.6.bisign 4F0BAAFDDC2C3474F7B310BAF221C22E
> addons/rhs_bmp_camo.pbo 5A9AED2283EE8B8E55BE07772CB9EF33
> addons/rhs_bmp_camo.pbo.rhsafrf.0.5.6.bisign 
> C5638F6DC62DED7C05877896096BE7CC
> addons/rhs_bmp3.pbo 1F8E4520CA673FE5F67E434D6C9C3EAA
> addons/rhs_bmp3.pbo.rhsafrf.0.5.6.bisign
> addons/rhs_bmp3_camo.pbo CE25F0037BCD19F55D6AA1CD3AEA0B86
> addons/rhs_bmp3_camo.pbo.rhsafrf.0.5.6.bisign 
> 9CF15ED151231E6C1E8A5E63C5AAD829
> addons/rhs_btr70.pbo 7FCC93BDDBE1A0573ABF146FA7C1FAD9
> addons/rhs_btr70.pbo.rhsafrf.0.5.6.bisign 61FD5A3D99F6A60BB31F0D396B19E5C5
> addons/rhs_btr70_camo.pbo 9A8F2BF875276FA1F7018F2D60C89D7A
>
> ```
>
> My tool works just fine, except it disagrees on the sorting
> (pastebinned at https://dpaste.org/UDiK):
>
> ```
> addons/rhs_bmp.pbo 2D08606D9BCB43E37A44CDBCD753F663
> addons/rhs_bmp.pbo.rhsafrf.0.5.6.bisign C5638F6DC62DED7C05877896096BE7CC
> addons/rhs_bmp3.pbo 1F8E4520CA673FE5F67E434D6C9C3EAA
> addons/rhs_bmp3.pbo.rhsafrf.0.5.6.bisign 2CCF421E08170964CF323A98725DDA6E
> addons/rhs_bmp3_camo.pbo CE25F0037BCD19F55D6AA1CD3AEA0B86
> addons/rhs_bmp3_camo.pbo.rhsafrf.0.5.6.bisign 
> 4F0BAAFDDC2C3474F7B310BAF221C22E
> addons/rhs_bmp_camo.pbo 5A9AED2283EE8B8E55BE07772CB9EF33
> addons/rhs_bmp_camo.pbo.rhsafrf.0.5.6.bisign 
> 9CF15ED151231E6C1E8A5E63C5AAD829
> addons/rhs_btr70.pbo 7FCC93BDDBE1A0573ABF146FA7C1FAD9
> ```
>
> In essence, to the .NET program `_` sorts before `3`, whereas for
> my Go program, it is the other way around.
>
> Now we could discuss at length which order is the correct one,
> but for my purposes (replicating the .NET tool) is what I
> strongly prefer. The alternative would be a breaking change in a
> larger system I do not control, and as such would be a lot of
> pain.
>
> So my question is: what is the easiest way to tell Go that `_`
> sorts before numerals here? My current sort helpers are (on the
> playground: https://play.golang.org/p/pQLeZN-fptY):
>
> ```
> type Files []ModFile
> type ModFile struct {
> Path string
> // Other fields here
> }
> func (f Files) Len() int { return len(f) }
> func (f Files) Swap(i, j int) { f[i], f[j] = f[j], f[i] }
> func (f Files) Less(i, j int) bool { return strings.ToLower(f[i].Path) < 
> strings.ToLower(f[j].Path) }
> ```
>
> (yes, the case folding is another peculiarity of the .NET tool)
>
> Best,
> Tobias
>

-- 
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/aee67181-62c7-4933-a9a5-90f45cf27067n%40googlegroups.com.


[go-nuts] Re: go list -u -m -json all

2021-07-25 Thread Tamás Gulácsi
go mod download
helped me.

jerome@gmail.com a következőt írta (2021. július 25., vasárnap, 9:49:40 
UTC+2):

>
> Hello,
> I am currently testing `go1.17rc1 linux/amd64` in my dev env.
>
> With this version `go list -u -m -json all` seems not work anymore (I use 
> it to know which module is outdated thanks to 
> https://github.com/psampaz/go-mod-outdated#usage)
>
> I have this error even if I do `go mod tidy` before to do `go list -u -m 
> -json all`
> go: updates to go.sum needed, disabled by -mod=readonly
>
>
> I don't know if it can be considered as issue with this rc.
>
> Jérôme
>
>
>

-- 
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/545ef823-c9b9-4f7d-a7cc-c3f936bc71d1n%40googlegroups.com.


[go-nuts] Re: Transaction Library Recommendations

2021-07-21 Thread Tamás Gulácsi
Hi,

1. Where are the transactions? I see only "up" and "down", and each can 
fail - even the "down" after a failed "up".
2. You spawn goroutines, and collect errors using append - that's racy. Run 
the tests with "-race" and see for yourself!

Tamás


dtmi...@gmail.com a következőt írta (2021. július 20., kedd, 23:17:49 
UTC+2):

> Hey, 
>
> I wrote this library a few years ago and in an effort to improve, was 
> wondering if anyone had any suggestions to this codebase? 
>
> I attempted to use the common library as my style guide. 
>
> I havn't found anything like it in, so I assumed most just wrote their own 
> implementation of a transaction abstraction. 
>
> Code:
> https://github.com/dtmirizzi/go-transact
>
> Thanks, 
> DT 
>

-- 
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/b80bbfb8-ff07-4a8f-962c-80934a76d468n%40googlegroups.com.


Re: [go-nuts] Re: C Third Party Lib CGO

2021-07-09 Thread Tamás Gulácsi
The runtime and checks does not know what's inside an uintptr, so 
converting an uintptr to a(n unsafe.)Pointer
triggers the warnings. Only the special specified cases are legal.

TL;DR; Do not use uintptr.
(More elaborate: do not use an uintptr to store and retrieve a pointer - 
just store the pointer directly).

Tamas

snmed a következőt írta (2021. július 9., péntek, 11:26:48 UTC+2):

> Yes uintptr is the address the C pointer is pointing to , right? So C 
> doesn't move any memory and therefore the address is still valid until 
> deleted in C code.
> If I take the value of uintptr variable,  convert it back with 
> unsafe.Pointer(uintptr) and pass it to a C function, does C not interpret 
> that as a C pointer pointing to the same address as uintptr holds?
> Therefore the conversion should be alright?
>
> Sorry for not getting it...
>
> Sandro
>
> Tamás Gulácsi schrieb am Freitag, 9. Juli 2021 um 11:12:22 UTC+2:
>
>> An uintptr *is not a pointer*, so 2. is false.
>> NOTHING at Go's side holds anything regarding MyAppHwnd, and it doesn't 
>> seem to be a pointer at all (just a number),
>> so converting that to an unsafe.Pointer is unsafe.
>>
>> The rules about uintptr are there for a reason!
>> Only the allowed use cases are guaranteed to have the desired effect, by 
>> preventing any memory movement
>> int that block of code.
>>
>> Tamas
>> snmed a következőt írta (2021. július 9., péntek, 8:21:37 UTC+2):
>>
>>> Thx Ian to pointing me to the documentation I read it, but still unsure 
>>> regarding my example. Probably rule number 4 could apply, so let me go 
>>> through my example and correct me if I'm wrong.
>>>
>>> 1. C.CreateApp() creates memory in C code and returns it as  C void 
>>> pointer
>>> 2. Go function CreateApp() returns that as MyAppHwnd (uintptr ) so 
>>> MyAppHwnd contains a valid C memory address
>>> 3. app variable holds still a valid C memory address as long as it is 
>>> not deleted in C code
>>> 4. So calling ShowApp() it should be legit to convert MyAppHwnd  back to 
>>> an unsafe.Pointer and cast it to C.MyAppPtr. It is still a valid memory 
>>> address in C and therefore should be interpreted as pointer in C, right?
>>>
>>> So therefore the warning can be ignored or do I miss something important?
>>>
>>> Cheers
>>> Sandro
>>>
>>>
>>> Ian Lance Taylor schrieb am Freitag, 9. Juli 2021 um 05:37:16 UTC+2:
>>>
>>>> On Thu, Jul 8, 2021 at 10:09 AM snmed  wrote: 
>>>> > 
>>>> > Thanks for your reply. I came across a similar solution today, I made 
>>>> a struct which is visible outside the package and use a private field 
>>>> myApp 
>>>> C.MyAppPtr to hide the C type. 
>>>> > I still wondering why the uintptr version works but shows a warning 
>>>> "possible misuse of unsafe.pointer", CGO documentation is not very clear 
>>>> to 
>>>> me about the intricacies of type conversions between Go and C. 
>>>>
>>>> There is a very limited number of cases in which it is OK to convert a 
>>>> pointer to uintptr. Those cases are described at 
>>>> https://golang.org/pkg/unsafe. 
>>>>
>>>> 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/b57a16e1-e6be-4ab8-bda7-67043d5dd79an%40googlegroups.com.


Re: [go-nuts] Re: C Third Party Lib CGO

2021-07-09 Thread Tamás Gulácsi
An uintptr *is not a pointer*, so 2. is false.
NOTHING at Go's side holds anything regarding MyAppHwnd, and it doesn't 
seem to be a pointer at all (just a number),
so converting that to an unsafe.Pointer is unsafe.

The rules about uintptr are there for a reason!
Only the allowed use cases are guaranteed to have the desired effect, by 
preventing any memory movement
int that block of code.

Tamas
snmed a következőt írta (2021. július 9., péntek, 8:21:37 UTC+2):

> Thx Ian to pointing me to the documentation I read it, but still unsure 
> regarding my example. Probably rule number 4 could apply, so let me go 
> through my example and correct me if I'm wrong.
>
> 1. C.CreateApp() creates memory in C code and returns it as  C void pointer
> 2. Go function CreateApp() returns that as MyAppHwnd (uintptr ) so 
> MyAppHwnd contains a valid C memory address
> 3. app variable holds still a valid C memory address as long as it is not 
> deleted in C code
> 4. So calling ShowApp() it should be legit to convert MyAppHwnd  back to 
> an unsafe.Pointer and cast it to C.MyAppPtr. It is still a valid memory 
> address in C and therefore should be interpreted as pointer in C, right?
>
> So therefore the warning can be ignored or do I miss something important?
>
> Cheers
> Sandro
>
>
> Ian Lance Taylor schrieb am Freitag, 9. Juli 2021 um 05:37:16 UTC+2:
>
>> On Thu, Jul 8, 2021 at 10:09 AM snmed  wrote: 
>> > 
>> > Thanks for your reply. I came across a similar solution today, I made a 
>> struct which is visible outside the package and use a private field myApp 
>> C.MyAppPtr to hide the C type. 
>> > I still wondering why the uintptr version works but shows a warning 
>> "possible misuse of unsafe.pointer", CGO documentation is not very clear to 
>> me about the intricacies of type conversions between Go and C. 
>>
>> There is a very limited number of cases in which it is OK to convert a 
>> pointer to uintptr. Those cases are described at 
>> https://golang.org/pkg/unsafe. 
>>
>> 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/e0b9351e-83ea-4d9f-9b1c-756385c9a132n%40googlegroups.com.


[go-nuts] Re: C Third Party Lib CGO

2021-07-08 Thread Tamás Gulácsi
Use *C.MyAppPtr on Go side, don't hide it behind an uintptr.

snmed a következőt írta (2021. július 7., szerda, 19:47:44 UTC+2):

>
> Hi all
>
> Once again I have a 3th party library which looks like this example: 
> https://play.golang.org/p/Ue9yQ8s8Ymq and I need it to integrate in our 
> go tool. The example is working but is still get the warning "
> possible misuse of unsafe.Pointer". 
>
> So my questions are:
>
>1. Can I use uintptr to hold the void pointer and pass it around go 
>functions?
>2. Can I ignore the warning "possible misuse of unsafe.pointer"?
>3. If not, what would be the proper approach for this example?
>
> Any help is much appreciated...
> Sandro
>
>
>

-- 
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/6cb297c4-1afe-4242-b112-b7392bc3c9e8n%40googlegroups.com.


[go-nuts] Re: It's possible to replace cgo memory allocator?

2021-06-12 Thread Tamás Gulácsi
You can use the LD_PRELOAD env var 
(https://www.ibm.com/docs/en/spectrum-symphony/7.2.1?topic=optimization-optimizing-memory-consumption-tcmalloc-jemalloc)
 
to use
jemalloc or tcmalloc, and debug with them.

di3go.b...@gmail.com a következőt írta (2021. június 10., csütörtök, 
21:19:15 UTC+2):

> I'm using cgo and struggling to find a memory leak which can be easily 
> detected if I can replace the cgo memory allocator to the one the C library 
> I'm using have because they did a leak detector implementation there.
>
> It's possible?
>
>
>

-- 
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/c352f12e-9b96-4230-8ec7-40a30ca34e1cn%40googlegroups.com.


[go-nuts] Re: Warning for look alike Unicode characters

2021-06-09 Thread Tamás Gulácsi
strings.EqualFold ?

Delta a következőt írta (2021. június 9., szerda, 23:30:04 UTC+2):

> Does the Go tool has any warning system for look alike Unicode 
> characters.
>
> http://www.unicode.org/Public/security/10.0.0/confusables.txt
>
>
> In rustc - 
>
> https://github.com/rust-lang/rust/blob/master/compiler/rustc_parse/src/lexer/unicode_chars.rs
>

-- 
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/77440e46-e4f2-49e4-9a3b-56c560b95755n%40googlegroups.com.


[go-nuts] Re: encoding/csv: getting a line number of current record when using csv.Reader

2021-04-09 Thread Tamás Gulácsi
And if your CSV is not so simple, then extract the number of "\n"-s found 
in the fields from the line count gathered by counting "\n"-s.

Or re-encode the csv into a "\n" counting io.Writer.

nikolay nikolay a következőt írta (2021. április 9., péntek, 7:03:49 UTC+2):

> If you CSV is simple, as in does not have multi-line values in columns, \n 
> in line ending — then you can create your own wrapper around io.Reader that 
> counts number of \n before returning to caller []bytes.
>
> -- Nikolay
>
> On Friday, April 9, 2021 at 1:50:10 AM UTC+8 peterGo wrote:
>
>> Dan,
>>
>> For Go 1.17:
>>
>> encoding/csv: add the ability to get the line number of a record #44221
>> https://github.com/golang/go/issues/44221
>>
>> Peter
>>
>> On Thursday, April 8, 2021 at 12:36:27 PM UTC-4 yodanj...@gmail.com 
>> wrote:
>>
>>> My need is similar to issue #26679 but not the same.
>>>
>>> I am using 1.15.8
>>>
>>> I have a need for the "current line number" when reading a csv file 
>>> (with Reader.Read() ) so that I can report errors in the data (not a 
>>> csv parsing error but errors in the data in the csv file).  In my case, a 
>>> comment character is being used to allow my user to provide comments in the 
>>> file for easier maintainability of their csv data.  Because of comments in 
>>> the file the record number and line number are not the same so any 
>>> reporting of errors to my user cannot point to any specific line number in 
>>> the file for the data error ... I have to either give info on the record to 
>>> my user or tell them the non-commented line number (neither being a 
>>> user-friendly option as they have to look through the file to see where the 
>>> real error is instead of going to a specific line number).
>>>
>>> Any way to get the true (starting) line number of the current record as 
>>> a file is being read using the Reader.Read() function?
>>>
>>> Thanks
>>> Dan
>>>
>>>

-- 
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/7d271822-3f71-41cd-b444-295500f9164an%40googlegroups.com.


[go-nuts] Re: MUnmap Mmapped file with Finalizer

2021-03-26 Thread Tamás Gulácsi
See https://github.com/tgulacsi/go/blob/master/iohlp/slurp.go

But mainly I use it at 
https://github.com/tgulacsi/go/blob/master/i18nmail/walk.go#L72 so all I 
want is an io.Reader, 
thus your example of golang.org/x/exp/mmap returning an io.ReaderAt may be 
enough, thanks!

Brian Candler a következőt írta (2021. március 26., péntek, 13:01:59 UTC+1):

> Is it even necessary?  Doesn't Go take care of unmapping the mmap'd region 
> when the object is garbage collected?
> https://github.com/golang/exp/blob/85be41e4509f/mmap/mmap_unix.go#L115
>
> If that's not true, can you show some more of your code to explain the 
> problem?
>

-- 
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/77bfa9d9-c6cc-4293-9cc5-f51be76947d0n%40googlegroups.com.


[go-nuts] MUnmap Mmapped file with Finalizer

2021-03-26 Thread Tamás Gulácsi
Hi,

I'm trying to create a nice api for slurping an io.Reader into memory (if 
size is under threshold), or into a temporary file that's Mmaped.

Everything works, if I give back an explicit io.Closer beside the []byte of 
the data, that Unmaps the []btye region when the caller has finished.

I wanted to get rid of that io.Closer, and use runtime.SetFinalizer(,...)

But that p is collected when not in use - even when a subslice is in use!

I've tried to runtime.SetFinalizer([0]),
but that complains that that address is not an allocated - which is 
understandable, as that's allocated by the OS, not by the Go GC.

So, how to Unmap only when all the references of the backing array gets 
garbage collected?

Or any other idea?

Thanks in advance,
Tamás Gulácsi

-- 
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/715e3f4e-5ff9-448e-a36a-f9bea601a3afn%40googlegroups.com.


Re: [go-nuts] Some questions about the memory allocation strategy of channel

2021-03-19 Thread Tamás Gulácsi
AFAIK when there's no pointer in elem (the channel's element's type), we 
can cheat/optimize (call as you wish),
and allocate the channel's backing memory AND all it's elements' memory at 
once, AS A BYTE ARRAY (nil is the second argument of mallocgc).
Then we can play unsafe tricks an treat it as proper channel and its buffer.

When there's pointer somewhere in the element's type, then - as the garbage 
collector must know each and every pointer's placement -
we don't play tricks, and give mallocgc the proper type information, and 
allocate the element buffer separate from the channel backing.

You'd have to repeat mallocgc's functionality to provide the gc with proper 
information, just to save one allocation.
That'd be too much work for less gain.

tianx...@gmail.com a következőt írta (2021. március 19., péntek, 4:37:00 
UTC+1):

> For this piece of code:
>
> case elem.ptrdata == 0:
>// Elements do not contain pointers.
>// Allocate hchan and buf in one call.
>c = (*hchan)(mallocgc(hchanSize+mem, nil, true))
>c.buf = add(unsafe.Pointer(c), hchanSize)
> default:
>// Elements contain pointers.
>c = new(hchan)
>c.buf = mallocgc(mem, elem, true)
> }
>
> Can I just understand that for the default case, when the compiler 
> executes the mallocgc() for c.buf, it would use reflect to build the 
> descriptor for the type of element? And if it allocates the both spaces in 
> one function call, it wouldn't build the descriptor for the gc, and gc 
> would find the descriptor later with more time, thus lead to worse 
> performance? Thanks a lot!
>
> Ian Lance Taylor  于2021年3月19日周五 上午2:50写道:
>
>> On Thu, Mar 18, 2021 at 9:55 AM Paul Zhang  wrote:
>> >
>> > I was reading the source code of makechan(), and these questions 
>> confused me. I would appreciate it if someone could help me.
>> >
>> > Q1. What does Elements do not contain pointers. mean? Does that means 
>> that the type of channel is not a pointer type (like chan int and chan 
>> *int)?
>>
>> It means that the element type of the channel is not a pointer and
>> also does not contain any pointers.  For example "struct { a, b int }"
>> does not contain any pointers, but "struct { a int; b []byte }" does
>> contain pointers.
>>
>>
>> > Q2. Why does the allocation strategy of memory allocation differ? It 
>> seems like the buf and the hchan should be allocated into one piece of 
>> continuous memory, if the "elements contains pointers", so what's the 
>> point? The logically continuous memory might not physically continuous.
>>
>> The garbage collector has to always know exactly where pointers are
>> stored in memory.  We could in principle use contiguous allocation for
>> the case where the element type contains pointers, but we would have
>> to build a description that tells the garbage collector exactly where
>> those pointers are.  Those descriptions are built by the compiler (on
>> tip, the code is in cmd/compile/internal/reflectdata/reflect.go), so
>> the compiler would have to build a new descriptor for every channel
>> type with an element type that contains pointers.  And the descriptor
>> would have to vary based on the channel size, so it would be based not
>> just on the channel type but also on the argument passed to "make".
>> Of course the argument passed to "make" can be a variable, so that
>> adds another complication.
>>
>> So it's probably possible to use a contiguous buffer here, but it's
>> not simple, and it's not the common case, and it's not clear that it
>> would be worth it.
>>
>> 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/984487a7-2700-4fc1-a89f-feba29136af6n%40googlegroups.com.


[go-nuts] Re: I want to save a file from an incoming POST request and upon request return the file in a GET request as JSON data.

2021-03-02 Thread Tamás Gulácsi
If I understand correctly, you receive "bodyBytes", store it in a file, and 
later want to serve it.
Then a `w.Write(b)` would suffice.
Or without reading the whole file into memory: `io.Copy(w, file)`.

hugh@gmail.com a következőt írta (2021. március 2., kedd, 14:12:22 
UTC+1):

> Here is what I have tried.
>
> type product struct {
> IDint `json:"id"`
> Description  string  `json:"description"`
> Price   float64  `json:"price"`
> Bin string  `json:"bin"`
> Qoh int  `json:"qoh"`
> }
> // * function to save data to a file *//
> func saveBackup(w http.ResponseWriter, r *http.Request) {
>
> type Resp struct {
> Message string `json:"message"`
> Affected string `json:"affected"`
> }
> resp:= Resp{}
>
>
> for k, v := range r.URL.Query() {
> kee = k
> val = v[0]
> }
> fileName :=  val // r.FormValue("filename")
>
> bodyBytes, err := ioutil.ReadAll(r.Body)
>
> var items product
> json.Unmarshal(bodyBytes, )
> fmt.Printf("%+v\n",items)
> f, err := os.Create(fileName)
> if err != nil {
> fmt.Println(err)
> return
> }
> l, err := f.Write(bodyBytes)
> if err != nil {
> fmt.Println(err)
> f.Close()
> return
> }
> fmt.Println(l, "bytes written successfully")
> err = f.Close()
> if err != nil {
> fmt.Println(err)
> return
> }
> resp.Message = "Save successful"
> resp.Affected = "Saved"
> respondWithJSON(w, http.StatusOK, resp)
>
> }
>
> // Retrieving the file ** //
>
> func getBackup(w http.ResponseWriter, r *http.Request) {
>
> kee := ""
> fileName := ""
> for k, v := range r.URL.Query() {
> kee = k
>  fileName = v[0]
> }
> var lines []product<=== []string  -  had this prior to scan Text
>
> file, err := os.Open(fileName)
> if err != nil {
> log.Fatal(err)
> }
> defer func() {
> if err = file.Close(); err != nil {
> log.Fatal(err)
> }
> }()
>
> // scanner := bufio.NewScanner(file)
> //for scanner.Scan() {
> //lines = append(lines, scanner.Text())
> //}
> b, err := ioutil.ReadFile(file)
>  append(lines, b)<== I know this is wrong
>
> response, _ := json.Marshal(lines)
>
> w.Header().Set("Content-Type", "application/json")
> w.WriteHeader(http.StatusOK)
> w.Write(response)
>
> }
>
> How can I return the result as a JSON file to the requesting application? 
> The client application parses the result to load into an array.
>

-- 
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/fc777ba8-980d-4569-bcce-1567a3d90becn%40googlegroups.com.


[go-nuts] Re: Recommendation for Fuzzed Types without Native On-Disk Format

2021-02-09 Thread Tamás Gulácsi
Use the []byte slice to fill your Table, and use the simplest possible 
encoding, which uses as few constraints as possible:
  1. Attrs on a line, separated by space, k-v separated by colon;
  2. Each Entry on a separate line, have the fields encoded as in 1.
  3. Decide how often do you want to fill Child - you can encode it as a 
number (position in the Entries list);
  4. What should/could be in Data? Or maybe a nil/not-nil is enough for 
your code to be excercised?

Filling with garbage is better than erroring out on filling!

matt@gmail.com a következőt írta (2021. február 8., hétfő, 22:07:39 
UTC+1):

> Hi all,
>
> I want to check the wisdom of the crowd on the following topic:
>
> Suppose I am interested in fuzz testing an API using dvyukov/go-fuzz 
> , and the primary API under test 
> accepts relatively complex composite data types itself: func F(*Table) 
> error, where the types below are minimally as complex as this:
>
> type Entry struct {
> Name  string
> Date  time.Date
> Child *Entry  // optional
> Data  interface{} // optional and user-defined
> }
>
> type Table struct {
> Attrs   map[string]string
> Entries []*Entry
> }
>
> go-fuzz expects the fuzz entrypoints to be func Fuzz(data []byte) int, 
> meaning *Table cannot be used directly without some intermediate 
> serialization and deserialization.  Suppose that *Table has no regular 
> on-disk format; what would you recommend as the approach to take toward 
> generating an initial corpus so that go-fuzz can explore the search space 
> and generate prospective crashers.
>
> I've toyed around a bit with taking representative values and encoding 
> them to disk with encoding/gob and then having go-fuzz deserialize, 
> validate, and reject bad gob value candidates by returning -1.  
> Notwithstanding any issues inherent to encoding/gob, this does not feel 
> like a particularly efficient on account of extraneous exercising of the 
> gob encoding format, when really func F(*Table) error is what I want to 
> exercise (as in commit my CPU cycles toward).
>
> Potentially there are a few other ways of encoding *Table, like Protocol 
> Buffers (with caveats), but encoding/binary is definitely out due to the 
> opaque size of *Table.  The point still stands: I would ideally not want to 
> exercise the serialization flow so much as handling of the type on which 
> the data is projected.
>
> What strategy would you use here?  I feel like there should be an obvious 
> choice under my nose that I am somehow omitting.  And no, I don't want 
> testing/quick for this, even though it can generate plenty of complex 
> composite types at runtime.   
>
> With warm regards,
>
> Matt T. Proud
>

-- 
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/c068a29f-8ade-4882-bb88-4cd024f3e87dn%40googlegroups.com.


[go-nuts] Re: Garbage Collector triggering when deleting an object

2020-11-23 Thread Tamás Gulácsi
There is a runtime.SetFinalizer, but it is not guaranteed to be run, 
anytime.
The most idiomatic and safe solution is to have a Close() method on the Go 
side, which frees the C side.
You may even add a Finalizer that panics if Close haven't been called 
before...

tokers a következőt írta (2020. november 23., hétfő, 4:17:18 UTC+1):

> There is a runtime.SetFinalizer function.
>
> On Sunday, November 22, 2020 at 8:13:22 PM UTC+8 Sean wrote:
>
>> I am writing a Golang wrapper for OpenAL-Soft.
>> I need to create some buffers. These operations are happening on the 
>> OpenAL-Soft side (So C functions). I am loading PCM data into buffers.
>>
>> Can I set up a trigger mechanism like "x.__del__" as in Python?
>>
>> I can set the garbage collector to follow some objects.
>> But I have to call some C functions (alDeleteBuffers) to delete buffers 
>> in OpenAL.
>>
>> I want garbage collector to run this function while deleting the object.
>>
>> Is this possible?
>>
>>

-- 
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/b71a4582-523d-448c-b404-050c84f932ecn%40googlegroups.com.


[go-nuts] Re: Any recommendation for structured logging library in Golang?

2020-11-18 Thread Tamás Gulácsi
This format is quite specific - roll your own!
See for example https://github.com/shamaazi/antilog or a derivative 
(github.com/UNO-SOFT/ulog) - very simple code, easy to modify.

My experience is against logfmt: is is nice, human-readable, but it is hard 
to log structures with it - you'll use fmt.Sprintf("%#v", structure), or 
json.Marshal(structure).

ChrisLu a következőt írta (2020. november 18., szerda, 5:21:48 UTC+1):

> I am considering moving from glog to structured logging. I tried logrus, 
> go-kit, uber/zap, but could not find one good fit. In short, this is the 
> desired format:
>
> [info][timestamp] [filename:line_number] message k1=v1 k2=v2 ...
>
> It shows the correct file name(need to pop out a few call stacks) and line 
> number in a customizable format, not as key-value pair for each line which 
> is just too verbose to have the extra "time=" "file=".
>
> Please let me know the one you actually use.
>
>
> Thanks!
> Chris
> -
> https://github.com/chrislusf/seaweedfs
>

-- 
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/9332eaf7-77af-455b-823d-dd8af97ba1e8n%40googlegroups.com.


Re: [go-nuts] How to drop old value in a channel salety

2020-11-14 Thread Tamás Gulácsi
If you read more than write, then you can use a sync.RWMutex an RLock when 
reading, Lock when writing.

Kurtis Rader a következőt írta (2020. november 15., vasárnap, 6:13:03 
UTC+1):

> On Sat, Nov 14, 2020 at 8:34 PM Robert Engels  
> wrote:
>
>> That wasn’t my take on the OPs need. He said the consumer is very 
>> expensive - implying to me they only want to process the latest. If 
>> dropping the oldest is viable you might as well drop all old entries and 
>> use the latest. 
>>
>
> The O.P. wrote two days ago:
>
> > Thanks. I want the receiver always get the relately new vaule,  I don't 
> want the sender blocked and I either choose drop the current value or the 
> first value of the channel. But I don't find a way to safely drop the first 
> value from the channel.
>
> In other words, they want the consumer to always fetch, and process, the 
> oldest available value. They want the producer(s) to always enqueue their 
> value; even if doing so requires dropping the oldest value from the queue 
> to make room for the new value. Whether that is sensible behavior, thus 
> requiring something other than a simple Go channel, is not obvious given 
> what the O.P. has written so far.
> -- 
> 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/4554312b-e4ea-4f5a-9782-7e2be4154e77n%40googlegroups.com.


[go-nuts] Re: Count of actually "processed" bytes from csv.Reader

2020-10-31 Thread Tamás Gulácsi
Why do you need an access to the internal bufio.Reader?

If you provide a bufio.Reader to bufio.NewReader, then it will NOT create a 
new reader, but give back your reader.
So if you keep your bufio.Reader, and give it to csv.NewReader, than you 
will have the same *bufio.Reader 
as what the csv.Reader's inner r !

Severyn Lisovsky a következőt írta (2020. október 31., szombat, 18:31:34 
UTC+1):

> Tamás Gulácsi, this was basically my initial idea to do that, but 
> unfortunately there is no access to internal bufio.Reader. See:
> https://golang.org/src/encoding/csv/reader.go#L170
>
> peterGo, my file is ~100GB so downloading it just for sake of splitting 
> doesn't make sense to me. I want for each worker to make use of 
> NewRangeReader 
> method 
> <https://godoc.org/cloud.google.com/go/storage#ObjectHandle.NewRangeReader> 
> to 
> download only related piece of the file. 
>
> ren...@ix.netcom.com ByteCount reader that wraps the underlying reader 
> wouldn't help because csv.Reader doesn't read from underlying reader 
> synchronically, it reads from bufio.Reader which buffers the bytes. So for 
> example if you read 1 row from CSV (eg. 10 bytes) from underlying io.Reader 
> will be 4096 bytes read. On the next csv.Reader.Read() call none of bytes 
> will be read from underlying io.Reader because it will take next row out of 
> the buffer
>
> On Saturday, October 31, 2020 at 6:02:32 PM UTC+1 Tamás Gulácsi wrote:
>
>> Give csv.NewReader your own *bufio.Reader. 
>> Regarding (https://pkg.go.dev/pkg/bufio/#NewReaderSize) if the 
>> underlying io.Reader is already a *bufio.Reader with a big enough size (and 
>> csv.NewReader uses the default 4k),
>> then the underlying reader is used, no new wrapping is introduced.
>>
>> This way if you use 
>>   cr := countingReader{Reader:r}  
>>   br := bufio.NewReader(cr)
>>   csvR := csv.NewReader(br)
>>
>> then cr.N - br.Buffered() is the number of bytes read by csv.Reader, the 
>> end of the last line read.
>>
>> Hope this helps.
>>
>> Severyn Lisovsky a következőt írta (2020. október 31., szombat, 3:17:26 
>> UTC+1):
>>
>>> Hi,
>>>
>>> I have difficulty counting bytes that were processed by csv.Reader 
>>> because it reads from internally created bufio.Reader. If I pass some 
>>> counting reader to csv.NewReader it will show not the actual number bytes 
>>> "processed" by csv.Reader to receive the output I get calling 
>>> csv.Reader.Read method, but the number of bytes copied to bufio.Reader's 
>>> buffer internally (some bytes may be read during next csv.Reader.Read call 
>>> from the buffer).
>>>
>>> Is there a way I can deal with this issue by not forking encoding/csv 
>>> package?
>>>
>>> To give you more high-level picture - I want to split remote csv file to 
>>> chunks. Each chunk should be standalone csv file - starting from actual 
>>> beginning of the line, ending with newline byte. So I'm trying to do the 
>>> following - split file size by the number of chunks, and for each chunk - 
>>> skip first bytes up to newline symbol and read to offset+chunkSize+[number 
>>> of bytes to the next newline symbol]
>>>
>>

-- 
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/bb5c7bfa-f604-4656-b335-a2e7c6682115n%40googlegroups.com.


[go-nuts] Re: Count of actually "processed" bytes from csv.Reader

2020-10-31 Thread Tamás Gulácsi
Give csv.NewReader your own *bufio.Reader. 
Regarding (https://pkg.go.dev/pkg/bufio/#NewReaderSize) if the underlying 
io.Reader is already a *bufio.Reader with a big enough size (and 
csv.NewReader uses the default 4k),
then the underlying reader is used, no new wrapping is introduced.

This way if you use 
  cr := countingReader{Reader:r}  
  br := bufio.NewReader(cr)
  csvR := csv.NewReader(br)

then cr.N - br.Buffered() is the number of bytes read by csv.Reader, the 
end of the last line read.

Hope this helps.

Severyn Lisovsky a következőt írta (2020. október 31., szombat, 3:17:26 
UTC+1):

> Hi,
>
> I have difficulty counting bytes that were processed by csv.Reader because 
> it reads from internally created bufio.Reader. If I pass some counting 
> reader to csv.NewReader it will show not the actual number bytes 
> "processed" by csv.Reader to receive the output I get calling 
> csv.Reader.Read method, but the number of bytes copied to bufio.Reader's 
> buffer internally (some bytes may be read during next csv.Reader.Read call 
> from the buffer).
>
> Is there a way I can deal with this issue by not forking encoding/csv 
> package?
>
> To give you more high-level picture - I want to split remote csv file to 
> chunks. Each chunk should be standalone csv file - starting from actual 
> beginning of the line, ending with newline byte. So I'm trying to do the 
> following - split file size by the number of chunks, and for each chunk - 
> skip first bytes up to newline symbol and read to offset+chunkSize+[number 
> of bytes to the next newline symbol]
>

-- 
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/c03c741f-a572-45bf-a503-76ecb61b71d1n%40googlegroups.com.


Re: [go-nuts] Should I always call runtime.LockOSThread() before calling C function?

2020-10-25 Thread Tamás Gulácsi
I'd put all that C-calling code in ONE goroution, with 
runtime.LockOSThread, and send commands to this thread through a channel, 
with a receiver chan for response, too.
This way only one goroutine needs LockOSThread, and only that pays the 
memory penalty.
If it becomes the bottleneck, you can easily ramp up several such 
"C-facing-worker-goroutines".

kongfam...@gmail.com a következőt írta (2020. október 25., vasárnap, 
15:39:31 UTC+1):

> Thanks Ian
>
> I found out that some libraries use thread-local storage
> I understood that it should be called runtime.LockOSThread() in my go 
> routine because each C function in for-loop can run on different thread
>
> I have one more question.
> If I called runtime.LockOSThread(), should I also call 
> runtime.UnlockOSThread()?
> When I called runtime.UnlockOSThread() in the end of go routine, heap 
> usage increased.
> I think thread-local storage's usage is accumulating because OS thread 
> isn't terminated
> Bacause of the above problem, I don't call runtime.UnlockOSThread() in the 
> end of go routine.
>
> 2020년 10월 25일 일요일 오전 2시 53분 42초 UTC+9에 Ian Lance Taylor님이 작성:
>
>> On Sat, Oct 24, 2020 at 10:30 AM ByeongJoon Gong 
>>  wrote: 
>> > 
>> > I'm developing speech-to-text inference server with cpp libraries 
>> (wav2letter) 
>> > 
>> > according to runtime docs (
>> https://golang.org/src/runtime/proc.go?s=108905:108924#L3803), 
>> > 
>> > "A goroutine should call LockOSThread before calling OS services or 
>> non-Go library functions that depend on per-thread state" 
>> > 
>> > The current server process as fallow 
>> > 
>> > func requestHandler(stream grpc) { 
>> > # runtime.LockOSThread() 
>> > var decoder unsafe.Pointer 
>> > init := false 
>> > 
>> > defer func() { 
>> > if decoder != nil { 
>> > C.resetDecoder(decoder) 
>> > } 
>> > } 
>> > for { 
>> > in, err := stream.Recv(); // grpc streaming 
>> > if err != nil { 
>> > break; 
>> > } 
>> > 
>> > if init == true { 
>> > C.decode(decoder, someTransformFunc(in.audio)) 
>> > } else { 
>> > decoder = C.getDecoder() 
>> > init = true 
>> > } 
>> > } 
>> > } 
>> > 
>> > Even if I don't call runtime.LockOSThread(), it works. 
>> > but memory leak occured when repeated. 
>> > ( VmData keep increasing on /proc/{pid}/status ) 
>> > 
>> > If I call runtime.LockOSThread(), it works good and no memory leak. 
>> > 
>> > why does a memory leak occur only when runtime.LockOSThread() is not 
>> called? 
>>
>> We don't know because we don't know how the C code works. If it uses 
>> per-thread state, then you need to call runtime.LockOSThread in Go. 
>> But we don't know what it does. You'll need to look at the C code. 
>>
>> 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/4f82b68e-ba91-44fa-bde3-a3bac67c2197n%40googlegroups.com.


Re: [go-nuts] Golang slow performance inside for loop MySQL Queries

2020-10-21 Thread Tamás Gulácsi
To reuse connections, and pay the slowness only on the first connection, set

Config.DB.SetMaxIdleConns(2)

Or something like that. 
As *sql.DB is a pool, this can keep two connections alive - one for your 
main query, and one for the per-row extra queries.

Bill a következőt írta (2020. október 21., szerda, 12:41:54 UTC+2):

> Hello, 
> I created the sql to fetch all info in one call instead of multiple calls 
> per each row.
>
> One thing I noticed about golang is that when I ping my Remote DB from 
> localhost (running in vscode) I get ping -> 1.573826274s. So I think this 
> is the reason that all my calls to db are delayed.
> Have you any idea what can be the issue? Maybe a clean install of Golang 
> in MacOSX could fix this issue? If I test the code in server (upload the 
> binary) the response time is normal (200ms - 300ms).
>
> My Code to ping: 
>
> begin := time.Now()
> err := Config.DB.Ping()
> log.Printf("Ping in %s (%v)", time.Since(begin), err)
> Στις Τρίτη, 20 Οκτωβρίου 2020 στις 8:19:16 μ.μ. UTC+3, ο χρήστης 
> mar...@gmail.com έγραψε:
>
>> Go's database layer is generally pretty quick, I use it a lot, but your 
>> code immediately sets off my DB alarms, because you are doing queries 
>> within the body of another query loop, which means you're opening up lots 
>> of connections, which could be slow.
>>
>> I'd reorganize as followd.
>>
>> - Cache the results of your first query into an array, it's only 6 
>> results.
>> - Create two prepared statements, one for each query inside the loop.
>> - Loop over your array of 6 results, and execute each prepared statement 
>> instead of parsing the query each time.
>>
>> By doing it this way, you should use 1 connection for the entire loop, 
>> and you'll only be parsing statements once each.
>>
>> If this is still slow, I'd start looking at your database performance, 
>> maybe.
>>
>> also, "defer rows.Close()" after you've checked if the query didn't 
>> result an error. There are no rows to close if err != nil
>>
>> -- Marcin
>>
>>
>>
>> On Tue, Oct 20, 2020 at 9:52 AM  wrote:
>>
>>> I use Go with github.com/go-sql-driver/mysql to connect to MySQL. The 
>>> performance in Go vs other languages is terrible or I'm missing something.
>>>
>>> I use Go for my REST API, an example is below:
>>>
>>> We have a table with posts. We fetch the posts, on each post we search 
>>> favorites table (if user has favorited this post and if he likes it).
>>>
>>> posts := make([]*MembersModel.Post, 0, 6)
>>>
>>> postsResults, err := Config.DB.Query("SELECT id, b64, title, 
>>> description, total_likes,  total_favorites, published_date  FROM posts 
>>> ORDER BY id DESC LIMIT 6")
>>>
>>> defer postsResults.Close()
>>>
>>> if err != nil {
>>> fmt.Println(err)
>>> panic(err.Error()) 
>>> }
>>>
>>> for postsResults.Next() {
>>> var postID int
>>> var b64 string
>>> var title string
>>> var description string
>>> var total_likes int
>>> var total_favorites int
>>> var published_date string
>>>
>>> postsResults.Scan(, , , , _likes, 
>>> _favorites, _date)
>>>
>>> var count int
>>> var favorited string
>>>
>>> fetchBookmarks := Config.DB.QueryRow("SELECT COUNT(*) FROM 
>>> favorites where userID = ? and postID = ? and status = ?", userID, postID, 
>>> "added").Scan()
>>>
>>> if fetchBookmarks != nil {
>>> fmt.Println("error")
>>> }
>>>
>>> if count == 0 {
>>> favorited = "no"
>>> } else {
>>> favorited = "yes"
>>> }
>>>
>>> var countSubmitted int
>>> var likedPost string
>>>
>>> fetchLikes := Config.DB.QueryRow("SELECT COUNT(*) FROM likes 
>>> where userID = ? and postID = ? and status=?", userID, postID, 
>>> "liked").Scan()
>>>
>>> if fetchLikes != nil {
>>> fmt.Println("error")
>>> }
>>>
>>> if countSubmitted == 0 {
>>> likedPost = "no"
>>> } else {
>>> likedPost = "yes"
>>> }
>>>
>>> post := {
>>> PostID:b64,
>>> Title: title,
>>> Description: description,
>>> Likes:   total_likes,
>>> PubDate:   published_date,
>>> Bookmarked:   favorited,
>>> Liked: likedPost,
>>> }
>>>
>>> posts = append(posts, post)
>>> }
>>>
>>> Average time to fetch these results -> 10 seconds!
>>>
>>> If I exclude the MYSQL calls inside the loop, the time to fetch these 
>>> results is 300ms.
>>>
>>> -- 
>>> 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 
>>> 

[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] ERRORLEVEL issue

2020-09-21 Thread Tamás Gulácsi
You're building src_go.exe (-o of go build), and running orabench.exe.


walter@gmail.com a következőt írta (2020. szeptember 21., hétfő, 
8:51:19 UTC+2):

> My code is here:
>
> [image: Screenshot 2020-09-21 084403.png]
>
> My script is here:
>
>
> [image: Screenshot 2020-09-21 084604.png]
>
> Logfile:
>
> [image: Screenshot 2020-09-21 084819.png]
>
> Same problem with os.Exit(1).
>
> What am I doing wrong?
> On Monday, 21 September 2020 at 05:38:11 UTC+2 Kurtis Rader wrote:
>
>> I also wrote a trivial Go program that did nothing more than 
>> `panic("WTF")` and it results in an exit status (ERRORLEVEL) of two in both 
>> a MSYS2 bash shell and a native cmd.exe shell. So, it is likely you are not 
>> testing what you think you are testing.
>>
>> On Sun, Sep 20, 2020 at 7:44 PM Walter Weinmann  
>> wrote:
>>
>>> Sorry - unfortunately I am a beginner.
>>>
>>> I have a Golang program that runs on an error and ends with panic(). 
>>> When running on Windows 10 the value of ERRORLEVEL is 0, the same happens 
>>> when the program is terminated with exit(1).
>>>
>>> What am I doing wrong? 
>>>
>>> -- 
>>> 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/a875f3d3-0f51-4cd8-91d5-5cf08f51223an%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/51159fc4-9399-4b92-8cbd-fd6ad97bbe28n%40googlegroups.com.


Re: [go-nuts] Re: Get request send me hmtl content but works fine from python and curl

2020-09-20 Thread Tamás Gulácsi
Which is absolutely non-standard :)
Headers are case-insensitive, so if the server relies on case, it's against 
the HTTP standard :)

remb...@gmail.com a következőt írta (2020. szeptember 20., vasárnap, 
13:18:09 UTC+2):

> Thanks everyone for your valuable feedback. 
> I was able to figure out the issue that was happening due to the 
> case-sensitive nature of the loginId header, which was being normalized in 
> golang. 
>
> So, after adding the below snippet i was able to make it work. 
>
> req.Header["loginId"] = []string{"0610A62F"}
>
> Ryan. 
>
>
>
>
>
> On Sun, 20 Sep 2020 at 14:49, Jesper Louis Andersen <
> jesper.lou...@gmail.com> wrote:
>
>> On Sun, Sep 20, 2020 at 8:10 AM burak serdar  wrote:
>>
>>> A GET request does not have a body.
>>>
>>>
>> Murky waters ahead.
>>
>> RFC 2616 explicitly states that a supplied body SHOULD be forwarded by 
>> the server on any request type. This has led some people to use bodies on 
>> GET requests; ElasticSearch I'm looking at you. However, the newer RFC 7231 
>> explicitly states that sending a body on a GET has no determined semantics 
>> and that "sound" clients ought to reject such bodies. But since RFC 2616 
>> existed at some point, you might still find certain APIs which do expect 
>> GET requests with bodies, however wrong that may seem.
>>
>> Getting rid of mistakes is really hard once they're been used in anger. 
>> And HTTP is riddled with design mistakes which shouldn't have been put in, 
>> in hindsight. Hopefully the new section of HTTP RFCs mean we can clean up 
>> over time as we proceed.
>>
>>  
>>
>> -- 
>>
> 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/CAGrdgiVfaVwmX5P%3DNd-ZPOcFOZP-XoETwAy5%2BBTVBzsRUi1F3A%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/524585fa-d34c-462f-96ba-0fab64966b2dn%40googlegroups.com.


Re: [go-nuts] Re: Get request send me hmtl content but works fine from python and curl

2020-09-20 Thread Tamás Gulácsi
Log the Python request, to see what it really sends - or recreate it with 
curl, which is easier to debug (--trace).

remb...@gmail.com a következőt írta (2020. szeptember 20., vasárnap, 
8:19:57 UTC+2):

> Thanks for taking time to answer my question. I have put the actual data 
> except the loginId header..
>
> https://play.golang.org/p/KrnxWLVj8s2
>
> But i still get the html content in golang but when i use python i get the 
> invalid api credentials. Due to incorrect loginId header. 
>
> import requests
>
> r = requests.get("https://www.dncscrub.com/app/main/rpc/scrub;, 
> params={'version': '5', "phoneList": "2123727200 <(212)%20372-7200>"},
>  headers={"loginId": "0610A62F"})
>
> print r.text
>
> So, responses are totally different from two languages. Python looks 
> correct. 
>
> Ryan
>
>
>
> On Sun, 20 Sep 2020 at 11:10, burak serdar  wrote:
>
>> On Sat, Sep 19, 2020 at 11:47 PM Tamás Gulácsi  
>> wrote:
>> >
>> > I bet requests (and curl) encodes the params as multipart/form-data, 
>> NOT query string.
>> > Do the same: https://play.golang.org/p/L4YryKNjju4
>>
>> A GET request does not have a body.
>>
>> I suggest you print out the request struct completely before
>> submitting it, with the headers and URL and everything, and then maybe
>> you can pinpoint the problem.
>>
>> >
>> > remb...@gmail.com a következőt írta (2020. szeptember 19., szombat, 
>> 20:44:54 UTC+2):
>> >>
>> >> I am trying to call a simple api by using golang. But, each time it 
>> sends me html content of login page instead of actual data. But same get 
>> request works from python and curl.
>> >>
>> >> package main
>> >>
>> >> import (
>> >> "fmt"
>> >> "io/ioutil"
>> >> "net/http"
>> >> "os"
>> >> )
>> >>
>> >> func main() {
>> >>
>> >> client := {}
>> >> req, err := http.NewRequest("GET", "https://www.lrn.com;, nil)
>> >> if err != nil {
>> >> os.Exit(1)
>> >> }
>> >>
>> >> q := req.URL.Query()
>> >> q.Add("phoneList", "XX")
>> >> q.Add("output", "json")
>> >> q.Add("version", "5")
>> >> //req.URL.RawQuery = q.Encode()
>> >> req.Header.Set("loginId", "XX")
>> >>
>> >> fmt.Println(req.URL.String())
>> >>
>> >> resp, err := client.Do(req)
>> >>
>> >> if err != nil {
>> >> fmt.Println("Errored when sending request to the server")
>> >> return
>> >> }
>> >>
>> >> defer resp.Body.Close()
>> >> resp_body, _ := ioutil.ReadAll(resp.Body)
>> >>
>> >> fmt.Println(resp.Status)
>> >> fmt.Println(string(resp_body))
>> >> }
>> >> Above script gives me html content of login page. But if i use python, 
>> it works just fine.
>> >>
>> >> import requests
>> >>
>> >> r=requests.get("https://www.lrn.com;, params = {'version':'5', 
>> "phoneList":"XX", "output":"json"}, 
>> headers={"loginId":"XX  "})
>> >>
>> >> print r.text
>> >>
>> >> Could someone please explain me what might be wrong in my golang 
>> script.
>> >>
>> >> Ryan.
>> >
>> > --
>> > 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/95c62bc9-7772-4309-907d-09590dae9a25n%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/CAMV2RqrvsdZvTfBax1Z2Ke0YL%3DzVtp20WBUMfnyB%2BLNwOVQLiw%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/c702afcd-a769-47a3-a628-b5705317e17bn%40googlegroups.com.


[go-nuts] Re: Get request send me hmtl content but works fine from python and curl

2020-09-19 Thread Tamás Gulácsi
I bet requests (and curl) encodes the params as multipart/form-data, NOT 
query string.
Do the same: https://play.golang.org/p/L4YryKNjju4

remb...@gmail.com a következőt írta (2020. szeptember 19., szombat, 
20:44:54 UTC+2):

> I am trying to call a simple api by using golang. But, each time it sends 
> me html content of login page instead of actual data. But same get request 
> works from python and curl. 
>
> package main
>
> import (
> "fmt"
> "io/ioutil"
> "net/http"
> "os"
> )
>
> func main() {
>
> client := {}
> req, err := http.NewRequest("GET", "https://www.lrn.com;, nil)
> if err != nil {
> os.Exit(1)
> }
>
> q := req.URL.Query()
> q.Add("phoneList", "XX")
> q.Add("output", "json")
> q.Add("version", "5")
> //req.URL.RawQuery = q.Encode()
> req.Header.Set("loginId", "XX")
>
> fmt.Println(req.URL.String())
>
> resp, err := client.Do(req)
>
> if err != nil {
> fmt.Println("Errored when sending request to the server")
> return
> }
>
> defer resp.Body.Close()
> resp_body, _ := ioutil.ReadAll(resp.Body)
>
> fmt.Println(resp.Status)
> fmt.Println(string(resp_body))
> }
> Above script gives me html content of login page. But if i use python, it 
> works just fine. 
>
> import requests
>
> r=requests.get("https://www.lrn.com;, params = {'version':'5', 
> "phoneList":"XX", "output":"json"}, 
> headers={"loginId":"XX  "})
>
> print r.text
>
> Could someone please explain me what might be wrong in my golang script. 
>
> Ryan. 
>

-- 
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/95c62bc9-7772-4309-907d-09590dae9a25n%40googlegroups.com.


Re: [go-nuts] Catch/handle cgo SIGSEGV

2020-09-18 Thread Tamás Gulácsi
Thank you very much!
It's way more complicated than I'd to deal with, so I'll leave it as is: 
crash the program if the C side gots a SIGSEGV.
Even the gRPC child seems more managable.

Ian Lance Taylor a következőt írta (2020. szeptember 17., csütörtök, 
22:11:18 UTC+2):

> On Thu, Sep 17, 2020 at 12:09 PM Tamás Gulácsi  wrote:
> >
> > Can you provide some skim of a C-side signal handler that could induce a 
> Go panic?
> > All I want is to have an error on Go side, instead of a crash (though it 
> may be safer to have a crash...).
>
> I can't think of any safe way that a C signal handler could cause a
> panic in the goroutine that called the C code that made the invalid
> memory reference.
>
> You could in principle have a C signal handler call a Go function that
> sends a message on a buffered channel that tells some other goroutine
> to panic. I think that could be safe. But it would not be safe for a
> C signal handler to call a Go function that calls panic. That would
> leave the program with most signals blocked.
>
> Ian
>
>
>
>
> > Ian Lance Taylor a következőt írta (2020. szeptember 17., csütörtök, 
> 21:00:52 UTC+2):
> >>
> >> On Thu, Sep 17, 2020 at 8:52 AM Tamás Gulácsi  
> wrote:
> >> >
> >> > I'm searching for help in https://github.com/godror/godror/issues/100 
> - I've added a recover, called debug.SetPanicOnFault, without success: the 
> extra free still panics with SIGSEGV, and the recover does not catch it (or 
> I coded it wrongly): 
> https://github.com/godror/godror/blob/2dab250ab19e158ba97699841f40c9de9d061f29/stmt.go#L306
> >> >
> >> > panic: 
> https://github.com/godror/godror/issues/100#issuecomment-694192603
> >>
> >> When a SIGSEGV occurs while running C code called via cgo, that
> >> SIGSEGV is not turned into a Go panic.
> >>
> >> It works this way both because 1) C is not a memory-safe language, and
> >> if the C code has not installed a signal handler there is no reason to
> >> think that the C code is prepared to carry on after a segmentation
> >> violation; 2) the mechanism that Go uses to turn a memory error into a
> >> panic can only work for Go code, not for C code.
> >>
> >> 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...@googlegroups.com.
> > To view this discussion on the web visit 
> https://groups.google.com/d/msgid/golang-nuts/30ca05ec-255b-4d67-b45f-89fde5396bb6n%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/aec55e3d-10ec-4542-8e67-9bae276d1a92n%40googlegroups.com.


Re: [go-nuts] Catch/handle cgo SIGSEGV

2020-09-17 Thread Tamás Gulácsi
Thanks, absolutely logical.

Can you provide some skim of a C-side signal handler that could induce a Go 
panic?
All I want is to have an error on Go side, instead of a crash (though it 
may be safer to have a crash...).

Ian Lance Taylor a következőt írta (2020. szeptember 17., csütörtök, 
21:00:52 UTC+2):

> On Thu, Sep 17, 2020 at 8:52 AM Tamás Gulácsi  wrote:
> >
> > I'm searching for help in https://github.com/godror/godror/issues/100 - 
> I've added a recover, called debug.SetPanicOnFault, without success: the 
> extra free still panics with SIGSEGV, and the recover does not catch it (or 
> I coded it wrongly): 
> https://github.com/godror/godror/blob/2dab250ab19e158ba97699841f40c9de9d061f29/stmt.go#L306
> >
> > panic: 
> https://github.com/godror/godror/issues/100#issuecomment-694192603
>
> When a SIGSEGV occurs while running C code called via cgo, that
> SIGSEGV is not turned into a Go panic.
>
> It works this way both because 1) C is not a memory-safe language, and
> if the C code has not installed a signal handler there is no reason to
> think that the C code is prepared to carry on after a segmentation
> violation; 2) the mechanism that Go uses to turn a memory error into a
> panic can only work for Go code, not for C code.
>
> 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/30ca05ec-255b-4d67-b45f-89fde5396bb6n%40googlegroups.com.


[go-nuts] Catch/handle cgo SIGSEGV

2020-09-17 Thread Tamás Gulácsi

I'm searching for help in https://github.com/godror/godror/issues/100 - 
I've added a recover, called debug.SetPanicOnFault, without success: the 
extra free still panics with SIGSEGV, and the recover does not catch it (or 
I coded it wrongly): 
https://github.com/godror/godror/blob/2dab250ab19e158ba97699841f40c9de9d061f29/stmt.go#L306

panic: https://github.com/godror/godror/issues/100#issuecomment-694192603

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/9c0a1e32-0738-4d93-811d-da1a5925aa9an%40googlegroups.com.


[go-nuts] Re: SQL Do I use Query or Exec?

2020-09-15 Thread Tamás Gulácsi
You can use EXPLAIN in PostgreSQL:

# explain with t as (select * from mantis_user_table) update 
mantis_user_table b set id=id where exists (select 1 from t where t.id = 
b.id); 

Update on mantis_user_table b (cost=23.19..41.92 rows=453 width=186)
  -> Hash Join (cost=23.19..41.92 rows=453 width=186) Hash Cond: (b.id = 
mantis_user_table.id)
...


# explain with t as (select * from mantis_user_table) select id from t;
Seq Scan on mantis_user_table (cost=0.00..15.44 rows=244 width=4) (1 row)


And the documentation says that MySQL has something alike.

If it is not a SELECT, then use ExecContext.
Rich a következőt írta (2020. szeptember 15., kedd, 16:19:51 UTC+2):

> I am writing a program in Go that allows users to put a query to a 
> database. This program uses multiple different drivers such as Postgres, 
> MySQL, and I want to be able to add other drivers as needed. This is 
> supposed to be something a user can use and depending on how the 
> configuration file is setup, connect to the server using the driver for 
> that server, as well as the configured username / password. I've integrated 
> it in to use my company's authentication system so that it can checks the 
> user's rights on the server to make sure that user has the authority to run 
> the commands specified. So a user can type ANY query they want -- select 
> update insert etc
>
> sqlrun -h mysqlsrv -e "select..."
>
>  sqlrun -h postgressrv -e "update ..."
>
> -h Specifies the host and in a config file the host is configured with the 
> driver, default database, username, and an encrypted password, I've 
> integrated it in to my company's authentication system to know if the user 
> can execute queries at all, or read only, or can write to the database. 
>
> So right now I pass all user given queries to sql.Query(). This works but 
> when the user is doing an update or insert -- I can't output the number of 
> rows impacted, for that I would need to use sql.Exec()
>
> What I want to know is if there is a way to get Rows impacted with a 
> query, or if there is a more comprehensive way to evaluate the query to 
> know if I should query or exec? I've looked into doing simple things like 
> look at the first word, if it's select, run query, if it's update or insert 
> run exec. The problem with that is the complexity of sql, you can have a 
> select statement that doesn't start with the word select... For example: 
> "WITH temporary_name AS (SELECT * FROM table_name)..."  I am sure there 
> could be others where Insert or Update are not always the first word of the 
> query... 
>

-- 
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/0c5fffd0-1fe7-4b76-934e-3c57527cdc2cn%40googlegroups.com.


[go-nuts] Re: How to send mail using .EML file/content in Golang?

2020-09-14 Thread Tamás Gulácsi
Sth. like 
```
var buf bytes.Buffer
buf.Reset()
fh, err := os.Open("path-to-eml")
if err != nil {
  return err
}
_, err = io.Copy(, fh)
fh.Close()
if err != nil {
return err
}
email, err := parsemail.Parse(bytes.NewReader(buf.Bytes()))
if err != nil { // handle error 
  return err
}
d := gomail.NewDialer(...)
sc, err := d.Dial()
if err != nil {
  return err
}
return sc.Send(email.From, []string{email.To}, buf)
```

Or if you don't want to read the whole email into memory (but I think 
parsemail already does it, unlike the standard net/mail),
you could create a little helper:
```
type copyWriterTo struct { r io.Reader }
func (cw copyWriterTo) WriteTo(w io.Writer) (int64, err) { return 
io.Copy(w, cw.r) }
```
and use it in `sc.Send`, instead of `buf`.

Tamás Gulácsi a következőt írta (2020. szeptember 14., hétfő, 6:17:42 
UTC+2):

> Use DialSender returned by gomail.Dial.
> You don't need the parsed message for it, just the from and to addresses, 
> and write the contents of the .eml file into the WriterTo as is.
>
> sandip bait a következőt írta (2020. szeptember 14., hétfő, 1:06:50 UTC+2):
>
>> I am using Standard *gomail <https://github.com/go-gomail/gomail>* package 
>> for sending mails in Golang. The mail generation part is happing from some 
>> other component which i am storing it in a particular location (i.e 
>> */path/sample.eml* file). And hence , i have pre-cooked mail body in 
>> .EML file which i just want process as a new mail. I am able to put/parse 
>> the .EML content by using the *parsemail 
>> <https://github.com/DusanKasan/parsemail>* package of *DusanKasan*. 
>> There are so many custom headers which i have already set in raw 
>> *sample.eml* file content which i want to send. It will be really 
>> helpful if i get an example code saying just pass *.eml* file as a input 
>> so that mail body will generate/render based on *.eml* file content.
>>
>> You can fine sample EML content string on *.EML 
>> <https://play.golang.org/p/mlDANqTLmj9>*Here is my basic mail sending 
>> code using *gomail <https://github.com/go-gomail/gomail>* 
>>
>> package.m := gomail.NewMessage() 
>> m.SetHeader("From", "al...@example.com") 
>> m.SetHeader("To", "b...@example.com", "co...@example.com") 
>> m.SetAddressHeader("Cc", "d...@example.com", "Dan") 
>> m.SetHeader("Subject", "Hello!") m.SetBody("text/html", "Hello Bob 
>> and Cora!") m.Attach("/home/Alex/lolcat.jpg") 
>>  d := gomail.NewDialer("smtp.example.com", 587, "user", "123456") // 
>> Send the email to Bob, Cora and Dan.
>> if err := d.DialAndSend(m); err != nil { panic(err) }
>>
>> Here is my eml parsing code using parsemail *parsemail 
>> <https://github.com/DusanKasan/parsemail>* package
>>
>> var reader io.Reader // this reads an email message 
>> email, err := parsemail.Parse(reader) // returns Email struct and error 
>> if err != nil { // handle error } fmt.Println(email.Subject) 
>> fmt.Println(email.From) 
>> fmt.Println(email.To) 
>> fmt.Println(email.HTMLBody) 
>>
>> Thanks & Regards,
>>
>>

-- 
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/b36be460-057f-4711-bdf0-79265b6623d0n%40googlegroups.com.


[go-nuts] Re: How to send mail using .EML file/content in Golang?

2020-09-13 Thread Tamás Gulácsi
Use DialSender returned by gomail.Dial.
You don't need the parsed message for it, just the from and to addresses, 
and write the contents of the .eml file into the WriterTo as is.

sandip bait a következőt írta (2020. szeptember 14., hétfő, 1:06:50 UTC+2):

> I am using Standard *gomail * package 
> for sending mails in Golang. The mail generation part is happing from some 
> other component which i am storing it in a particular location (i.e 
> */path/sample.eml* file). And hence , i have pre-cooked mail body in .EML 
> file which i just want process as a new mail. I am able to put/parse the 
> .EML content by using the *parsemail 
> * package of *DusanKasan*. There 
> are so many custom headers which i have already set in raw *sample.eml* file 
> content which i want to send. It will be really helpful if i get an example 
> code saying just pass *.eml* file as a input so that mail body will 
> generate/render based on *.eml* file content.
>
> You can fine sample EML content string on *.EML 
> *Here is my basic mail sending 
> code using *gomail * 
>
> package.m := gomail.NewMessage() 
> m.SetHeader("From", "al...@example.com") 
> m.SetHeader("To", "b...@example.com", "co...@example.com") 
> m.SetAddressHeader("Cc", "d...@example.com", "Dan") 
> m.SetHeader("Subject", "Hello!") m.SetBody("text/html", "Hello Bob 
> and Cora!") m.Attach("/home/Alex/lolcat.jpg") 
>  d := gomail.NewDialer("smtp.example.com", 587, "user", "123456") // Send 
> the email to Bob, Cora and Dan.
> if err := d.DialAndSend(m); err != nil { panic(err) }
>
> Here is my eml parsing code using parsemail *parsemail 
> * package
>
> var reader io.Reader // this reads an email message 
> email, err := parsemail.Parse(reader) // returns Email struct and error if 
> err != nil { // handle error } fmt.Println(email.Subject) 
> fmt.Println(email.From) 
> fmt.Println(email.To) 
> fmt.Println(email.HTMLBody) 
>
> Thanks & Regards,
>
>

-- 
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/4f235f30-c515-4896-9162-531917b717f8n%40googlegroups.com.


Re: [go-nuts] database/sql doesn't return error for query-string-destination if NULL bug or feature

2020-09-11 Thread Tamás Gulácsi
database/sql.DB is a pool. If you don't want to close it, 
SetMaxIdleConns(1), or better, use a db.Conn().

stephan...@gmail.com a következőt írta (2020. szeptember 11., péntek, 
21:02:26 UTC+2):

> On Friday, 11 September 2020 at 21:04:11 UTC+3 mar...@gmail.com wrote:
>
>> Which sqlite driver are you using? That sounds like a bug.
>>
>
> "github.com/mattn/go-sqlite3"
>  
>
>>
>> On Fri, Sep 11, 2020 at 10:56 AM Stephan Lukits wrote:
>>
>>> I passed a string-type pointer (as last destination) to a sql.DB.Query 
>>> call which had a NULL value as field value. No error was returned
>>
>>
> Here I was wrong.  The error is returned by the Scan(...)-call (which I 
> didn't catch, these are my first steps with go ...)
> The reason why I was fixated on the Query-call was the way I tracked the 
> cause:
> I printed the functioning and not functioning DB-connection and saw that 
> they differ
> &{0 {:memory: 0xc0e0e0} 0 {0 0} [0xc000126a20] ...
> &{0 {:memory: 0xc0e0e0} 0 {0 0} [] ...
> at the slice. Pinging the non-functioning DB-connection put a new addres 
> into the empty slice, so I assumed that this slice holds the open 
> connections.
> Then I narroed the two lines until I found the line where the switch to 
> the empty slice happand which was oddly the Query-call.
>
> The Questions which remain are, dose this connection gets closed allways 
> when an error appears? Is it a bug? 
> Can I use the API to figure if this connection was closed? Ping doesn't 
> work because it just creates a new connection and pretends everything is 
> fine.
> My settings are:
> .SetMaxOpenConns(1)
> .SetConnMaxLifetime(0)
> .SetConnMaxIdleTime(0)
> (because I really don't want this connection to close ;)
>  
> Thanks Stephan
>

-- 
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/284619bd-4576-4d73-8696-fbd0e1865a34n%40googlegroups.com.


[go-nuts] Re: Anyone successfully connecting to Oracle (11g) from Go?

2020-09-07 Thread Tamás Gulácsi
Wow, have you reverse-engineered the Oracle SQL.NET connection? Or the Java 
thin client?
Is this legal at all?
Though I'd pay a limb for a C-less native, pure Go client...

Samy Sultan a következőt írta (2020. szeptember 7., hétfő, 20:01:46 UTC+2):

> I make a new package go-ora it is pure go oracle client no need for 
> instant client at all no need for environmental vars just 
> go-get the package and run you program
>
> https://github.com/sijms/go-ora.git
>
> في الخميس، 5 يونيو 2014 في تمام الساعة 12:03:05 ص UTC+3، كتب ‪Ron Gidron‬‏ 
> رسالة نصها:
>
>> OK so after a long debugging session I ened up finding that there are 
>> type mismatches happening when running go 1.3. I have (for now) updated my 
>> oci8 driver and filed a report here 
>> https://github.com/mattn/go-oci8/issues/27
>>
>> Solved for me.
>>
>> Thanks,
>> --Ron
>>
>>
>> On Thursday, May 29, 2014 8:18:31 PM UTC+3, Ron Gidron wrote:
>>
>>> I am running OS X 10.9.3 and attempting to work with an amazon RDS 
>>> instance. I have instantclient installed and working properly but am 
>>> hitting walls trying to setup basic connectivity to it from my Go 
>>> environment. I tried using both an ODBC driver (failed to install with 
>>> missing .h files complaints) and also tried 
>>> https://github.com/tgulacsi/goracle with no luck. 
>>> Is anyone out these setup with Go server connected to Oracle (from a 
>>> Mac?) and willing to share some code snippets / install directions?
>>>
>>> Thanks!
>>> --Ron
>>>
>>

-- 
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/d5b13267-d5f2-4838-a218-690144524c57n%40googlegroups.com.


Re: [go-nuts] Debug http calls made using go http client

2020-08-23 Thread Tamás Gulácsi
You can print every step with net/http/httptrace 's ClientTrace.

krishna...@gmail.com a következőt írta (2020. augusztus 23., vasárnap, 
15:55:50 UTC+2):

> Hello Dimas,
>
> Thank you for your response. My application is running in a kubernetes 
> cluster and I will not be able to run TCPMon or TCPDump separately, as 
> access is restricted. I was looking for something that can be embedded 
> within the go application.
>
> Regards,
> *Krishna*
>
>
>
> On Sun, Aug 23, 2020 at 7:13 PM Dimas Prawira  
> wrote:
>
>> There are several tools which you can use to help to inspect, 
>>
>> 1. TCPmon, is a java-based tool for inspecting http call in between 
>> server and client. TCPmon also can be used to simulate slow connection. 
>>
>> Work mechanism of TCPmon is as a proxy. So if I describe it as below
>>
>> [Your apps] ---> [tcpmon] ---> [server]
>>
>> 2. TCPdump, is a linux app which can be use to dump TCP connection in and 
>> out. This can be help to inspect HTTP request / HTTP come to the server.
>>
>> 3. Traceroute
>> You may want to inspect / trace connection from your server to vendor's 
>> server using traceroute, maybe the problem is in the connection.
>>
>> Hope that's helpful
>>
>> On Sat, Aug 22, 2020, 01:59 krishna...@gmail.com  
>> wrote:
>>
>>> Hello Gophers,
>>>
>>> I am making multiple http calls from my go application to an external 
>>> vendor's http server using the go standard http client. I've set a 10 
>>> second timeout for my context. Everything works fine. 
>>>
>>> However, I get random timeouts in my application due to these HTTP 
>>> calls. On further investigation, I found that the http calls to the 
>>> vendor's server take longer than 10 seconds. 
>>> During this period of timeouts, the vendor says they've not received any 
>>> HTTP requests. How do I verify that the http requests are made from my app? 
>>> If the requests are made from my app, how can I figure out what's causing 
>>> the delay?
>>>
>>> I tried debugging using the HTTP client trace, but couldn't find any 
>>> actionable information. Any suggestions on how to debug/fix this issue ?
>>>
>>> Thanks
>>> - Krishna 
>>>
>>> -- 
>>> 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/2d454dda-6670-48ef-85a2-0a42216dcd29n%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/72972301-5163-4dfd-8886-1ed2b8efadc4n%40googlegroups.com.


  1   2   3   4   5   6   >