[go-nuts] how golang stores variables in the computer’s memory?

2021-08-16 Thread Miraddo
Hello, 

Yesterday, I had an awesome interview, and I found I don't know anything 
about  `Golang`  in deep, so I decided to learn more about the compiler and 
memory and every part of  `Golang`  in deep. I guess I had a lot of 
questions :)

Do you have any reference to know, How `Golang` stores' variables in memory 
?

How does `Golang` point a variable to the memory location, and how is 
reference stored?

And any suggestion it would be helpful for me, what should I do to learn 
more deep concepts.

Thank you,
Milad

-- 
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/941b2637-58f2-4794-b798-c1798012f741n%40googlegroups.com.


Re: [go-nuts] Go mod ignoring project sub-modules

2021-08-16 Thread Nicholas Bunn
Thanks for the prompt response, Jay!

And thanks for clearing that up, it's good to know that it's intended to 
run as such. For the purpose and scale of this project, it's a bit easier 
to keep everything together and use sub-modules where I can (this hasn't 
been an issue thus far) so I'd like to keep it this way if possible. If I 
do stick with this approach, how could I work around this? Intuitively, I'd 
just install the sub-modules individually - but this is what produced my 
issue in the first place. Is there a way I can force the modules to exist 
on their own instead of as modules in a subdirectory?
On Monday, August 16, 2021 at 8:35:15 PM UTC+2 jayc...@google.com wrote:

> Hi Nic,
>
> This is actually working as intended, though I don't think we've 
> adequately documented it. I've sent CL 342531 
>  to mention this 
> in the reference documentation.
>
> In short though, files in a subdirectory that contains a go.mod file are 
> considered part of a different module, so when you download the module in 
> the parent directory, the files in that subdirectory are not included.
>
> In many cases, putting multiple Go modules in the same repository can be 
> counter-intuitive. I'd only recommend it in situations where you have 
> multiple projects that need to be released and versioned independently. If 
> the projects are tightly couple and need to be released together it may be 
> better to have them in one module.
>
> On Mon, Aug 16, 2021 at 9:11 AM Nicholas Bunn  
> wrote:
>
>> Hi all,
>>
>> Hoping someone can give me a bit of assistance here. I'm busy refactoring 
>> a gRPC project of mine so that all proto files are generated into a single, 
>> "protoFile" directory, instead of having the generated files living under 
>> the service's directory. My idea is to have the generated files implemented 
>> as modules, allowing any client to access them from this central location.
>>
>> The issue I've run into is the "module found ... but does not contain 
>> ..." one. I've hit this a couple of times before (as anyone new to Go 
>> modules does, I'm sure) and can usually solve it by cleaning modcache 
>> and/or re-initialising the modules. However this time the usual solutions 
>> haven't helped much. I've attempted to implement semantic versioning on my 
>> Github too, which didn't resolve anything either. Go get fetches the 
>> correct version of my project directory (
>> github.com/NicholasBunn/mastersCaseStudy), but when I check my pkg 
>> directory, it's omitted all subfolders that contain Go modules (including 
>> all go services with a go.mod file). 
>>
>> The project is hosted at github.com/NicholasBunn/mastersCaseStudy, with 
>> the generated protos living in protoFiles/go. If you'd like to try and 
>> re-create the issue, cd into 
>> mastersCaseStudy/services/authenticationService, and run "go mod tidy". 
>> This service makes use of the generated protos living in 
>> mastersCaseStudy/protoFiles/go/authenticationService/v1, which has its 
>> go.mod and go.sum files, but the "go mod tidy" fails on my side with the 
>> error mentioned above.
>>
>> Hoping I've just misunderstood something with Go modules and someone here 
>> can throw me onto the right path again!
>>
>> Thanks in advance,
>> Nic
>>
>> -- 
>> 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/aa1c413c-f9ab-4be0-822d-4886a37bbdb9n%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/88085943-fb64-429d-999b-e0df384d2e33n%40googlegroups.com.


Re: [go-nuts] go.sum security error

2021-08-16 Thread Igor Chubin
Thank you for your answers!

This is definitely not in the cache, because the problem exists everywhere,
including new containers and new cloud instances.

I can test it with 1.14 and 1.15 too; I don't think that the problem is 
specific
for 1.13 only.

You say, that the security error is correct: but how can it be then it is 
detected
by only one of the Go versions and is ignored by the other?
On Monday, August 16, 2021 at 7:57:49 PM UTC+2 jayc...@google.com wrote:

> This doesn't seem like a problem with Go versions. The security error is 
> correct. It looks like the module author tagged v1.1.1 with this go.mod 
> file  then 
> changed the tag to point to a different commit with this file 
> .
>
> The file on proxy.golang.org is hashed and included in the checksum 
> database. It looks like the hash 
>  there is 
> h1:fx79htI3WZA9Ep4jphLFq06l3iRDimfOWTrkKOz+OAA=. 
> That's the correct one to put in go.sum.
>
> The incorrect version may still be in your module cache. You can remove it 
> with `go clean -modcache` (though this will remove everything else there, 
> too).
>
> On Mon, Aug 16, 2021 at 9:19 AM Ian Lance Taylor  wrote:
>
>> On Mon, Aug 16, 2021 at 9:11 AM Igor Chubin  wrote:
>> >
>> > When I generate `go.sum` with go 1.16, and try to build it with go of a 
>> different version (1.13 in my case), I get `SECURITY ERROR`:
>> >
>> > ```
>> > verifying github.com/tredoe/osu...@v1.1.1/go.mod 
>> : checksum mismatch
>> > downloaded: h1:fx79htI3WZA9Ep4jphLFq06l3iRDimfOWTrkKOz+OAA=
>> > go.sum: h1:wHEjPMepmXQXkZhf9H4sQcCtmC45KuFo5VR97zG9/dY=
>> >
>> > SECURITY ERROR
>> > This download does NOT match an earlier download recorded in go.sum.
>> > The bits may have been replaced on the origin server, or an attacker may
>> > have intercepted the download attempt.
>> >
>> > For more information, see 'go help module-auth'.
>> > ```
>> >
>> > Then I fix (remove the entry and run `go mod tidy`) `go.sum` and try to 
>> build it again. It works with 1.13, but the problem appears then with 1.16.
>> >
>> > So there should be some incompatibility between Go 1.13 and 1.16 (not 
>> sure exactly when it was introduced, so don't know about 1.14 and 1.15).
>> >
>> > Currently, as a workaround, I added this to my build scripts:
>> >
>> > ```
>> > sed -i /osutil/d go.sum \
>> > && go mod download github.com/tredoe/osutil
>> > ```
>> >
>> > but it is not a real solution, of course.
>> >
>> > How am I supposed to fix this problem?
>>
>> We no longer support Go 1.13.
>>
>> You can probably work around this problem temporarily and insecurely
>> by setting the GONOSUMDB environment variable.  See the mentions of
>> GONOSUMDB at https://pkg.go.dev/cmd/go.
>>
>> Ian
>>
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "golang-nuts" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to golang-nuts...@googlegroups.com.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/golang-nuts/CAOyqgcV56QDp1TXTaNsr%2B1UezWmoMbYRhk8iN58bDRzJq83xkA%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/a095f4e5-5aa4-40a6-83af-ea87c0c7f39cn%40googlegroups.com.


Re: [go-nuts] Re: How to retrieve content of file uploaded using "curl --upload-file ..." way in Go HttpServer

2021-08-16 Thread Roland Müller
Hello,


Am Mo., 16. Aug. 2021 um 19:11 Uhr schrieb Kannan S :

> messageId := r.URL.Query()["id"][0]
>  out, err := os.Create("./upload/" + messageId + ".mp3")
>
> in your original example file name is retrieved from the request.URL.Path
rather than from an variable named 'id' using request.URL.Query().

This should work when using the curl command below (haven't tried it out).
The line replaces the two lines setting messageId and using message Id for
creating the upload file.

out,err = os.Create("./upload/" + r.URL.Path[1:])

BR,
Roland



>  if err != nil {
> fmt.Fprintf(w, "Unable to create the file for writing. Check your
> write access privilege")
> return
>  }
>
> i added this portion but i am getting an error while trying to upload a
> file using curl
>  error in server is :panic serving 10.10.20.55:62253: runtime error:
> index out of range [0] with length 0
> what is the reason??
>
> On Wednesday, 8 October 2014 at 02:14:13 UTC+5:30 Tobias S. wrote:
>
>> Sorry, I misunderstood your problem, so my code snippet is probably
>> useless for you. But I found this:
>>
>> http://stackoverflow.com/questions/25804092/golang-upload-file-err-runtime-error-index-out-of-range
>> The code sample can be fixed easily and should be what you are after.  I
>> guess it is also better to adapt then the example you cited.
>>
>> Entefunc webUploadHandler(w http.ResponseWriter, r *http.Request) {
>>
>>  file, header, err := r.FormFile("file") // the FormFile function takes
>> in the POST input id file
>>
>>  if err != nil {
>> fmt.Fprintln(w, err)
>> return
>>  }
>>  defer file.Close()
>>
>>  // My error comes here
>>
>>  messageId := r.URL.Query()["id"][0]
>>  out, err := os.Create("./upload/" + messageId + ".mp3")
>>
>>  if err != nil {
>> fmt.Fprintf(w, "Unable to create the file for writing. Check your
>> write access privilege")
>> return
>>  }
>>  defer out.Close()
>>
>>  // write the content from POST to the file
>>  _, err = io.Copy(out, file)
>>  if err != nil {
>> fmt.Fprintln(w, err)
>>  }
>>
>>  fmt.Fprintf(w,"File uploaded successfully : ")
>>  fmt.Fprintf(w, header.Filename)
>>
>> }r code here...
>>
>>
>>
>> On Tuesday, October 7, 2014 3:56:09 PM UTC+2, Budh Ram wrote:
>>
>>> Hi Guys,
>>>
>>> I am newbie in Go language.
>>> I am writing a small HttpServer in Go where I want to upload file to
>>> this server using curl approach as:
>>>
 curl --upload-file foo.txt http://localhost:9090/rp.txt

>>>
>>> I am getting following server logs:
>>> https://gist.github.com/budhrg/355126ba4f03d32008e0
>>>
>>> I searched through docs, existing codes but the closest I found is file
>>> upload using web
>>> .
>>>
>>> Following is my code for HttpServe which I need to update to accept file
>>> content and save in server:
>>>
 package main


> import (

   "fmt"

   "net/http"

 )


> func main() {

   http.Handle("/", http.HandlerFunc(upload))

   http.ListenAndServe("localhost:9090", nil)

 }


> func upload(w http.ResponseWriter, req *http.Request) {

   fmt.Fprintf(w, "file name is : %s",req.URL.Path[1:])

   fmt.Println("method :", req.Method)

   fmt.Println("FileSize : ", req.ContentLength)

   fmt.Println("Header : ",req.Header)

   fmt.Println("Body : ",req.Body)

   fmt.Println("Post form : ",req.PostForm)

 }



>>> Please help
>>>
>>>
>> --
> 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/85f0c138-86e0-4d31-8c1b-4c6ef1d161a6n%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/CA%2B8p0G0K4QiA3F%3DL69zkM0k6QwyDD_sJKKgy-ZT2BnUsHP4maw%40mail.gmail.com.


[go-nuts] How to install previous release of protobuf on windows?

2021-08-16 Thread Igor Gelin
How to install previous release of protobuf on windows?

-- 
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/5c13bbe7-08bb-4fc9-a648-76084fa82299n%40googlegroups.com.


[go-nuts] Go 1.17 is released

2021-08-16 Thread Michael Knyszek
Hello gophers,

We just released Go 1.17

To find out what has changed in Go 1.17, read the release notes:
https://golang.org/doc/go1.17

You can download binary and source distributions from our download page:
https://golang.org/dl/

If you have Go installed already, an easy way to try go1.17
is by using the go command:
$ go get golang.org/dl/go1.17
$ go1.17 download

To compile from source using a Git clone, update to the release with
"git checkout go1.17" and build as usual.

Thanks to everyone who contributed to the release!

Cheers,
Michael and Dmitri for the Go Team

-- 
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/CAN%3D%2BcNqFSAm8Er%3D09Yn825eKB4rgg24ZMvGSp5467ffj1z5Pdw%40mail.gmail.com.


Re: [go-nuts] Go mod ignoring project sub-modules

2021-08-16 Thread 'Jay Conrod' via golang-nuts
Hi Nic,

This is actually working as intended, though I don't think we've adequately
documented it. I've sent CL 342531
 to mention this in
the reference documentation.

In short though, files in a subdirectory that contains a go.mod file are
considered part of a different module, so when you download the module in
the parent directory, the files in that subdirectory are not included.

In many cases, putting multiple Go modules in the same repository can be
counter-intuitive. I'd only recommend it in situations where you have
multiple projects that need to be released and versioned independently. If
the projects are tightly couple and need to be released together it may be
better to have them in one module.

On Mon, Aug 16, 2021 at 9:11 AM Nicholas Bunn 
wrote:

> Hi all,
>
> Hoping someone can give me a bit of assistance here. I'm busy refactoring
> a gRPC project of mine so that all proto files are generated into a single,
> "protoFile" directory, instead of having the generated files living under
> the service's directory. My idea is to have the generated files implemented
> as modules, allowing any client to access them from this central location.
>
> The issue I've run into is the "module found ... but does not contain ..."
> one. I've hit this a couple of times before (as anyone new to Go modules
> does, I'm sure) and can usually solve it by cleaning modcache and/or
> re-initialising the modules. However this time the usual solutions haven't
> helped much. I've attempted to implement semantic versioning on my Github
> too, which didn't resolve anything either. Go get fetches the correct
> version of my project directory (github.com/NicholasBunn/mastersCaseStudy),
> but when I check my pkg directory, it's omitted all subfolders that contain
> Go modules (including all go services with a go.mod file).
>
> The project is hosted at github.com/NicholasBunn/mastersCaseStudy, with
> the generated protos living in protoFiles/go. If you'd like to try and
> re-create the issue, cd into
> mastersCaseStudy/services/authenticationService, and run "go mod tidy".
> This service makes use of the generated protos living in
> mastersCaseStudy/protoFiles/go/authenticationService/v1, which has its
> go.mod and go.sum files, but the "go mod tidy" fails on my side with the
> error mentioned above.
>
> Hoping I've just misunderstood something with Go modules and someone here
> can throw me onto the right path again!
>
> Thanks in advance,
> Nic
>
> --
> 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/aa1c413c-f9ab-4be0-822d-4886a37bbdb9n%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/CAGCADbZWkk%3DMz1G_vgU57hnaUd3ONbG4XbzS4p2HO3Gcqe7nqQ%40mail.gmail.com.


Re: [go-nuts] go.sum security error

2021-08-16 Thread 'Jay Conrod' via golang-nuts
This doesn't seem like a problem with Go versions. The security error is
correct. It looks like the module author tagged v1.1.1 with this go.mod file
 then
changed the tag to point to a different commit with this file
.

The file on proxy.golang.org is hashed and included in the checksum
database. It looks like the hash
 there
is h1:fx79htI3WZA9Ep4jphLFq06l3iRDimfOWTrkKOz+OAA=.
That's the correct one to put in go.sum.

The incorrect version may still be in your module cache. You can remove it
with `go clean -modcache` (though this will remove everything else there,
too).

On Mon, Aug 16, 2021 at 9:19 AM Ian Lance Taylor  wrote:

> On Mon, Aug 16, 2021 at 9:11 AM Igor Chubin  wrote:
> >
> > When I generate `go.sum` with go 1.16, and try to build it with go of a
> different version (1.13 in my case), I get `SECURITY ERROR`:
> >
> > ```
> > verifying github.com/tredoe/osutil@v1.1.1/go.mod: checksum mismatch
> > downloaded: h1:fx79htI3WZA9Ep4jphLFq06l3iRDimfOWTrkKOz+OAA=
> > go.sum: h1:wHEjPMepmXQXkZhf9H4sQcCtmC45KuFo5VR97zG9/dY=
> >
> > SECURITY ERROR
> > This download does NOT match an earlier download recorded in go.sum.
> > The bits may have been replaced on the origin server, or an attacker may
> > have intercepted the download attempt.
> >
> > For more information, see 'go help module-auth'.
> > ```
> >
> > Then I fix (remove the entry and run `go mod tidy`) `go.sum` and try to
> build it again. It works with 1.13, but the problem appears then with 1.16.
> >
> > So there should be some incompatibility between Go 1.13 and 1.16 (not
> sure exactly when it was introduced, so don't know about 1.14 and 1.15).
> >
> > Currently, as a workaround, I added this to my build scripts:
> >
> > ```
> > sed -i /osutil/d go.sum \
> > && go mod download github.com/tredoe/osutil
> > ```
> >
> > but it is not a real solution, of course.
> >
> > How am I supposed to fix this problem?
>
> We no longer support Go 1.13.
>
> You can probably work around this problem temporarily and insecurely
> by setting the GONOSUMDB environment variable.  See the mentions of
> GONOSUMDB at https://pkg.go.dev/cmd/go.
>
> Ian
>
> --
> You received this message because you are subscribed to the Google Groups
> "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to golang-nuts+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/golang-nuts/CAOyqgcV56QDp1TXTaNsr%2B1UezWmoMbYRhk8iN58bDRzJq83xkA%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/CAGCADbZu-XbqPfj81u0Nh36vSYAP6CC31XF_vr%3DuvfZ1-s8jDQ%40mail.gmail.com.


Re: [go-nuts] go.sum security error

2021-08-16 Thread Ian Lance Taylor
On Mon, Aug 16, 2021 at 9:11 AM Igor Chubin  wrote:
>
> When I generate `go.sum` with go 1.16, and try to build it with go of a 
> different version (1.13 in my case), I get `SECURITY ERROR`:
>
> ```
> verifying github.com/tredoe/osutil@v1.1.1/go.mod: checksum mismatch
> downloaded: h1:fx79htI3WZA9Ep4jphLFq06l3iRDimfOWTrkKOz+OAA=
> go.sum: h1:wHEjPMepmXQXkZhf9H4sQcCtmC45KuFo5VR97zG9/dY=
>
> SECURITY ERROR
> This download does NOT match an earlier download recorded in go.sum.
> The bits may have been replaced on the origin server, or an attacker may
> have intercepted the download attempt.
>
> For more information, see 'go help module-auth'.
> ```
>
> Then I fix (remove the entry and run `go mod tidy`) `go.sum` and try to build 
> it again. It works with 1.13, but the problem appears then with 1.16.
>
> So there should be some incompatibility between Go 1.13 and 1.16 (not sure 
> exactly when it was introduced, so don't know about 1.14 and 1.15).
>
> Currently, as a workaround, I added this to my build scripts:
>
> ```
> sed -i /osutil/d go.sum \
> && go mod download github.com/tredoe/osutil
> ```
>
> but it is not a real solution, of course.
>
> How am I supposed to fix this problem?

We no longer support Go 1.13.

You can probably work around this problem temporarily and insecurely
by setting the GONOSUMDB environment variable.  See the mentions of
GONOSUMDB at https://pkg.go.dev/cmd/go.

Ian

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CAOyqgcV56QDp1TXTaNsr%2B1UezWmoMbYRhk8iN58bDRzJq83xkA%40mail.gmail.com.


[go-nuts] Go mod ignoring project sub-modules

2021-08-16 Thread Nicholas Bunn
Hi all,

Hoping someone can give me a bit of assistance here. I'm busy refactoring a 
gRPC project of mine so that all proto files are generated into a single, 
"protoFile" directory, instead of having the generated files living under 
the service's directory. My idea is to have the generated files implemented 
as modules, allowing any client to access them from this central location.

The issue I've run into is the "module found ... but does not contain ..." 
one. I've hit this a couple of times before (as anyone new to Go modules 
does, I'm sure) and can usually solve it by cleaning modcache and/or 
re-initialising the modules. However this time the usual solutions haven't 
helped much. I've attempted to implement semantic versioning on my Github 
too, which didn't resolve anything either. Go get fetches the correct 
version of my project directory (github.com/NicholasBunn/mastersCaseStudy), 
but when I check my pkg directory, it's omitted all subfolders that contain 
Go modules (including all go services with a go.mod file). 

The project is hosted at github.com/NicholasBunn/mastersCaseStudy, with the 
generated protos living in protoFiles/go. If you'd like to try and 
re-create the issue, cd into 
mastersCaseStudy/services/authenticationService, and run "go mod tidy". 
This service makes use of the generated protos living in 
mastersCaseStudy/protoFiles/go/authenticationService/v1, which has its 
go.mod and go.sum files, but the "go mod tidy" fails on my side with the 
error mentioned above.

Hoping I've just misunderstood something with Go modules and someone here 
can throw me onto the right path again!

Thanks in advance,
Nic

-- 
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/aa1c413c-f9ab-4be0-822d-4886a37bbdb9n%40googlegroups.com.


[go-nuts] Re: How to retrieve content of file uploaded using "curl --upload-file ..." way in Go HttpServer

2021-08-16 Thread Kannan S
messageId := r.URL.Query()["id"][0]
 out, err := os.Create("./upload/" + messageId + ".mp3")

 if err != nil {
fmt.Fprintf(w, "Unable to create the file for writing. Check your write 
access privilege")
return
 }

i added this portion but i am getting an error while trying to upload a 
file using curl
 error in server is :panic serving 10.10.20.55:62253: runtime error: index 
out of range [0] with length 0
what is the reason??

On Wednesday, 8 October 2014 at 02:14:13 UTC+5:30 Tobias S. wrote:

> Sorry, I misunderstood your problem, so my code snippet is probably 
> useless for you. But I found this:
>
> http://stackoverflow.com/questions/25804092/golang-upload-file-err-runtime-error-index-out-of-range
> The code sample can be fixed easily and should be what you are after.  I 
> guess it is also better to adapt then the example you cited. 
>
> Entefunc webUploadHandler(w http.ResponseWriter, r *http.Request) {
>
>  file, header, err := r.FormFile("file") // the FormFile function takes in 
> the POST input id file
>
>  if err != nil {
> fmt.Fprintln(w, err)
> return
>  }
>  defer file.Close()
>
>  // My error comes here
>
>  messageId := r.URL.Query()["id"][0]
>  out, err := os.Create("./upload/" + messageId + ".mp3")
>
>  if err != nil {
> fmt.Fprintf(w, "Unable to create the file for writing. Check your 
> write access privilege")
> return
>  }
>  defer out.Close()
>
>  // write the content from POST to the file
>  _, err = io.Copy(out, file)
>  if err != nil {
> fmt.Fprintln(w, err)
>  }
>
>  fmt.Fprintf(w,"File uploaded successfully : ")
>  fmt.Fprintf(w, header.Filename)
>
> }r code here...
>
>
>
> On Tuesday, October 7, 2014 3:56:09 PM UTC+2, Budh Ram wrote:
>
>> Hi Guys,
>>
>> I am newbie in Go language.
>> I am writing a small HttpServer in Go where I want to upload file to this 
>> server using curl approach as:
>>
>>> curl --upload-file foo.txt http://localhost:9090/rp.txt
>>>
>>
>> I am getting following server logs: 
>> https://gist.github.com/budhrg/355126ba4f03d32008e0
>>
>> I searched through docs, existing codes but the closest I found is file 
>> upload using web 
>> .
>>
>> Following is my code for HttpServe which I need to update to accept file 
>> content and save in server:
>>
>>> package main
>>>
>>>
 import (
>>>
>>>   "fmt"
>>>
>>>   "net/http"
>>>
>>> )
>>>
>>>
 func main() {
>>>
>>>   http.Handle("/", http.HandlerFunc(upload))
>>>
>>>   http.ListenAndServe("localhost:9090", nil)
>>>
>>> }
>>>
>>>
 func upload(w http.ResponseWriter, req *http.Request) {
>>>
>>>   fmt.Fprintf(w, "file name is : %s",req.URL.Path[1:])
>>>
>>>   fmt.Println("method :", req.Method)
>>>
>>>   fmt.Println("FileSize : ", req.ContentLength)
>>>
>>>   fmt.Println("Header : ",req.Header)
>>>
>>>   fmt.Println("Body : ",req.Body)
>>>
>>>   fmt.Println("Post form : ",req.PostForm)
>>>
>>> }
>>>
>>>
>>>
>> Please help
>>  
>>
>

-- 
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/85f0c138-86e0-4d31-8c1b-4c6ef1d161a6n%40googlegroups.com.


[go-nuts] go.sum security error

2021-08-16 Thread Igor Chubin
When I generate `go.sum` with go 1.16, and try to build it with go of a 
different version (1.13 in my case), I get `SECURITY ERROR`:

```
verifying github.com/tredoe/osutil@v1.1.1/go.mod: checksum mismatch
downloaded: h1:fx79htI3WZA9Ep4jphLFq06l3iRDimfOWTrkKOz+OAA=
go.sum: h1:wHEjPMepmXQXkZhf9H4sQcCtmC45KuFo5VR97zG9/dY=

SECURITY ERROR
This download does NOT match an earlier download recorded in go.sum.
The bits may have been replaced on the origin server, or an attacker may
have intercepted the download attempt.

For more information, see 'go help module-auth'.
```

Then I fix (remove the entry and run `go mod tidy`) `go.sum` and try to 
build it again. It works with 1.13, but the problem appears then with 1.16.

So there should be some incompatibility between Go 1.13 and 1.16 (not sure 
exactly when it was introduced, so don't know about 1.14 and 1.15).

Currently, as a workaround, I added this to my build scripts:

```
sed -i /osutil/d go.sum \
&& go mod download github.com/tredoe/osutil
```

but it is not a real solution, of course.

How am I supposed to fix this 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/2e92eb04-f11e-434f-9dbf-b92878dd61c5n%40googlegroups.com.