[go-nuts] Re: Named results allocated on stack instead of register?

2021-09-20 Thread tapi...@gmail.com
It looks this is related to code inlining.
If we add //go:noinline directive for the two functions,
then they have no performance difference.

On Monday, September 20, 2021 at 12:39:51 PM UTC-4 tapi...@gmail.com wrote:

> Sometimes, a function with named results is slower.
> For example: https://play.golang.org/p/wvWkfSRqDLr
>
> The generated directives are almost the same for the two
> functions with a named and unnamed result, except one difference.
> For the function with the named result, the result represents as "".ret
> in the generated directive, but for the function with the unnamed result,
> the result represents as "".~r1 in the generated directive.
>
> Does "".ret means the result is allocated on stack? 
>
>
>

-- 
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/f962870a-17a4-4691-8f8d-282d27373018n%40googlegroups.com.


Re: [go-nuts] Idea extending xerror.As

2021-09-20 Thread Andrey T.

... or, to put a crazy idea out there, we need to ask for extension of 
switch statement to support (v, err) tuples for a case argument...
On Sunday, September 19, 2021 at 3:43:36 PM UTC-6 david@gmail.com wrote:

> On Sun, Sep 19, 2021 at 5:19 PM roger peppe  wrote:
>
>> In some ways, the existing API is arguably more ergonomic than the 
>> originally proposed generic version, as it's possible to use `errors.As` in 
>> a switch statement (eg to test several possible types of error) which isn't 
>> possible with the multi-return `As` variant.
>>
>
> Hmm, that's a good point.
> However, the main reason I like the two-return-value version more is that 
> you can use it like a normal type-assertion in an if-statement's init 
> section.
>
>
>> A minor variant of the existing API could be:
>>
>> ```
>> func As[E error](err error, asErr *E) bool
>> ```
>> which makes the API a little clearer without changing the usage. Sadly we 
>> can't make that change without breaking compatibility.
>>
>> Unfortunately, in order to use this proposed version, you still need to 
> pre-declare the variables for each type before the switch/case.
> I've honestly found it more ergonomic to use a if/else if/ block rather 
> than a switch/case because it lets me contain the scope of these variables 
> anyway.
>
> I suppose a simple wrapper that can be used with type-assertions inside a 
> switch/case block would be:
> ```
> func AsBool[E error](err error, asErr error) bool {
> ae, ok := As[E](err)
> if ok {
>  asErr = ae
> }
> return ok
> }
> ```
> (this would definitely need a better name)
>
> Then you'd be able to almost treat your switch/case like a type-switch 
> without needing to pre-declare a variable for every case.
>
> ```
> var asErr error
> switch {
>case errors.AsBool[*os.PathError](err, ):
>fmt.Printf("Path Error! ae: %v", asErr.(*os.PathError))
>case errors.AsBool[syscall.Errno](err, ):
>fmt.Printf("ae: %d", asErr.(syscall.Errno))
> }
> ```
>
> However, I think it would be nicer to use the (originally proposed) 
> two-return errors.As with if/else if.
>
> ```
> if pe, ok := errors.As[*os.PathError](err); ok {
> fmt.Printf("Path Error: %v", pe)
> } else if en, ok := errors.As[syscall.Errno](err); ok {
> fmt.Printf("errno %[1]d: %[1]s", en)
> }
> ```
>
> Since it looks like the dev.typeparams branch has been merged into master, 
> I was just thinking about how we'd add the two-return-value/generic version 
> of As to the errors package (for go 1.18).
> Given that the original proposal's code works pretty much as-is, I think 
> the biggest barrier would be a good name. (given that As is already taken)
>
>>
>> On Sun, 19 Sep 2021, 21:15 David Finkel,  wrote:
>>
>>>
>>>
>>>
>>> On Sun, Sep 19, 2021 at 4:02 PM David Finkel  
>>> wrote:
>>>
 You might be interested in the original draft proposal for errors.As:

 https://go.googlesource.com/proposal/+/master/design/go2draft-error-inspection.md#the-is-and-as-functions

 In particular, it originally specified that errors.As would take a 
 type-parameter. (the version of generics that was proposed concurrently 
 with that proposal was not accepted so they had to go with the current 
 (clunkier) interface).

>>>
>>> Hmm, actually, the code in that proposal for the generic version of 
>>> errors.As works almost unchanged: 
>>> https://go2goplay.golang.org/p/ddPDlk00Cbl (I just had to change the 
>>> type-parameter syntax)
>>>
>>>
 On Sun, Sep 19, 2021 at 5:33 AM Haddock  wrote:

>
> I like the way error handling is done in the xerror package. Things 
> become more concise, but remain very easy to read and understand as in 
> plain Go errorhandling.
>
> Here is the example of how to use xerror.As:
>
> _, err := os.Open("non-existing")
> if err != nil {
> var pathError *os.PathError
> if xerrors.As(err, ) {
> fmt.Println("Failed at path:", pathError.Path)
> }
> }
>
> My idea is to make this even shorter like this:
>
> _, err := os.Open("non-existing")
> myerrors.As(err, os.PathError) {
>  pathError -> fmt.Println("Failed at path:", pathError.Path)
> }
>
> Think something like that has so far not been suggested. That's why I 
> thought it is justified to drop comment.
>
> myerrors.As would also do the check if err is nil. The code in my 
> sample is not valid Go code, I know. It is only pseudo code to show the 
> idea.
>
> -- 
> 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/629e6763-36a9-4d7d-991c-fd71dd384d0en%40googlegroups.com

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

2021-09-20 Thread Glen Newton
Hello,

Thanks for this, and also sorry for the lazy question.

My testing on my machine indicates a limit of 2GB total limit on compile: 

too much data in section SXCOFFTOC (over 2e+09 bytes)
too much data in section SDATA (over 2e+09 bytes)

I have built a bash script that creates large random files of a fixed size 
and then generates a short Go program that embeds them, increasing the 
number of files with each run, so you can see when your compile fails. 
You can find the bash and instructions here: 
https://github.com/gnewton/test_go_embed

I just threw it together, so might be a little rough around the edges. 
Feedback welcome.

Question: Wondering why the above error complains about too much data in 
*two* sections: are the embedded files stored across multiple sections (I 
know nothing of how this is done internally to the elf format)?

Thanks,
Glen

On Monday, September 20, 2021 at 5:11:45 PM UTC-4 Ian Lance Taylor wrote:

> On Mon, Sep 20, 2021 at 2:04 PM Glen Newton  wrote:
> >
> > I am testing this with an increasing number of 1GB files. At 3 files, 
> and I am getting this error:
> >
> > compile: writing output: write $WORK/b001/_pkg_.a: no space left on 
> device
> >
> > I haven't been able to find how to change $WORK to point to a larger 
> partition. Suggestions?
>
> Set the TMPDIR environment variable to control temporary files in
> general, or the GOTMPDIR environment variable to control just
> temporary files created by the go tool.
>
> 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/65e20ea9-cbe4-4cf1-823d-a8fa063ae44fn%40googlegroups.com.


[go-nuts] [ANN] Pack: Interfaces for LZ77-based data compression

2021-09-20 Thread Andy Balholm
Many data-compression schemes are conceptually composed of two steps: 
LZ77 (finding repeated sequences) and entropy encoding. But I've never 
found a compression library that treats those steps as separate 
components. So I made one: github.com/andybalholm/pack. It defines 
interfaces for the two stages, and includes a few example 
implementations (Encoders for snappy, flate, and brotli; and 
MatchFinders based on snappy and flate.BestSpeed).


Of course the abstraction of using these interfaces has a performance 
penalty, but my flate.BestSpeed implementation is still faster than the 
standard library flate package.


The biggest disadvantage of dividing things up like this is that it 
prevents taking advantage of unique features of a compression format, 
like brotli's static dictionary, or feedback from the entropy encoder to 
the LZ77 stage like brotli and zopfli use at higher compression levels. 
But by breaking the problem up into smaller pieces, it makes it much 
easier to experiment with compression algorithms.


Andy

--
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/052bed1d-79f8-0910-7517-53e8cb04eced%40balholm.com.


Re: [go-nuts] Re: Generating go code using go templates

2021-09-20 Thread Denis Cheremisov
Trees although better in general than template still have one critical 
disadvantage: it is hard to control a code they produces.I tried approaches 
with templates, line by line and trees. Line by line is generally the best 
of them.
понедельник, 20 сентября 2021 г. в 23:15:22 UTC+3, chet...@gmail.com: 

> Yes. Generating large portions of code via templates is going to be hard. 
> Especially reusing and maintaining it.
> There is an excellent library called jennifer - 
> https://github.com/dave/jennifer that lets you generate Go code by 
> building the syntax tree. The examples make it super simple to get started. 
> You might want to check it out.
>
> On Monday, September 20, 2021 at 12:29:51 PM UTC-7 va...@selfip.ru wrote:
>
>> I'm writing a code generator from protobuf via templates and i can say - 
>> debugging it is very hard. When you have big files you can't check syntax 
>> easily, don't know how it looks and if you have errors in the template it 
>> is really hard to fix them.
>> So the protoc-gen-go case is preferable.
>>
>> вс, 19 сент. 2021 г. в 04:33, Denis Cheremisov :
>>
>>> Templates is the worst approach to code generation IMO. Take a look how 
>>> they do this in protoc-gen-go: 
>>>
>>> https://github.com/protocolbuffers/protobuf-go/blob/b92717ecb630d4a4824b372bf98c729d87311a4d/cmd/protoc-gen-go/internal_gengo/main.go#L83
>>>
>>> I am using very similar approach, albeit I prefer format lines, it looks 
>>> like:
>>> [image: Screenshot from 2021-09-19 04-22-26.png]
>>>
>>> Templates may be OK only in trivial cases. Once you need something less 
>>> trivial it is getting harder and harder to reason how the final code will 
>>> look like with them
>>> and you will end up with bunch of hard to manage templates. Unlike it, 
>>> line-by-line code generation keep staying close to the final code.
>>> вторник, 7 сентября 2021 г. в 22:53:51 UTC+3, amitl...@gmail.com: 
>>>

 Hi gophers,
 I wrote https://github.com/fluhus/goat for generating go code in my 
 projects. I hope it can help you too. It's a minimal tool that takes a 
 text/template  template as input, 
 runs it on the given parameters and gofmt's the output. You can also use 
 it 
 on non-go-source.
 Feedback is welcome.

 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...@googlegroups.com.
>>> To view this discussion on the web visit 
>>> https://groups.google.com/d/msgid/golang-nuts/406179d9-c8f5-497d-8832-ea04ff9d03b3n%40googlegroups.com
>>>  
>>> 
>>> .
>>>
>>
>>
>> -- 
>> 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/a34732e5-e6c5-4a91-9c55-2aa57d927b01n%40googlegroups.com.


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

2021-09-20 Thread Ian Lance Taylor
On Mon, Sep 20, 2021 at 2:04 PM Glen Newton  wrote:
>
> I am testing this with an increasing number of 1GB files. At 3 files, and I 
> am getting this error:
>
> compile: writing output: write $WORK/b001/_pkg_.a: no space left on device
>
> I haven't been able to find how to change $WORK to point to a larger 
> partition. Suggestions?

Set the TMPDIR environment variable to control temporary files in
general, or the GOTMPDIR environment variable to control just
temporary files created by the go tool.

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/CAOyqgcXPizSd-BN1aWzidPsf%2Bcu3erfw4%2BaaA6m_gLUZLR2o0g%40mail.gmail.com.


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

2021-09-20 Thread Glen Newton
Thanks.

I am testing this with an increasing number of 1GB files. At 3 files, and I 
am getting this error:

compile: writing output: write $WORK/b001/_pkg_.a: no space left on device

I haven't been able to find how to change $WORK to point to a larger 
partition. Suggestions?

Oh, running:   
  go1.17.1.linux-amd64
  go version go1.17.1 linux/amd64
  Linux OptiPlex-7010 5.8.0-63-generic #71-Ubuntu SMP Tue Jul 13 15:59:12 
UTC 2021 x86_64 x86_64 x86_64 GNU/Linux


Thanks,
Glen


On Monday, September 20, 2021 at 12:25:08 PM UTC-4 Ian Lance Taylor wrote:

> On Mon, Sep 20, 2021 at 9:20 AM Glen Newton  wrote:
> >
> > The maximum size for any single embedded file as []byte is 4GB. What is 
> the total maximum size for all embedded files included this way in a Go 
> binary?
> > Also, are there any platform dependencies?
>
> The total maximum size for all embedded files depends on what the
> platform is able to support. And, yes, there are platform
> dependencies. Most 32-bit platforms can't support a total size larger
> than 2G. Most 64-bit platforms have much larger limits, though I
> don't know specifically what they are offhand.
>
> 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/2c69cff2-fd89-449c-8afb-c98236a09543n%40googlegroups.com.


Re: [go-nuts] Re: Generating go code using go templates

2021-09-20 Thread Chetan Gowda
Yes. Generating large portions of code via templates is going to be hard. 
Especially reusing and maintaining it.
There is an excellent library called jennifer - 
https://github.com/dave/jennifer that lets you generate Go code by building 
the syntax tree. The examples make it super simple to get started. You 
might want to check it out.

On Monday, September 20, 2021 at 12:29:51 PM UTC-7 va...@selfip.ru wrote:

> I'm writing a code generator from protobuf via templates and i can say - 
> debugging it is very hard. When you have big files you can't check syntax 
> easily, don't know how it looks and if you have errors in the template it 
> is really hard to fix them.
> So the protoc-gen-go case is preferable.
>
> вс, 19 сент. 2021 г. в 04:33, Denis Cheremisov :
>
>> Templates is the worst approach to code generation IMO. Take a look how 
>> they do this in protoc-gen-go: 
>>
>> https://github.com/protocolbuffers/protobuf-go/blob/b92717ecb630d4a4824b372bf98c729d87311a4d/cmd/protoc-gen-go/internal_gengo/main.go#L83
>>
>> I am using very similar approach, albeit I prefer format lines, it looks 
>> like:
>> [image: Screenshot from 2021-09-19 04-22-26.png]
>>
>> Templates may be OK only in trivial cases. Once you need something less 
>> trivial it is getting harder and harder to reason how the final code will 
>> look like with them
>> and you will end up with bunch of hard to manage templates. Unlike it, 
>> line-by-line code generation keep staying close to the final code.
>> вторник, 7 сентября 2021 г. в 22:53:51 UTC+3, amitl...@gmail.com: 
>>
>>>
>>> Hi gophers,
>>> I wrote https://github.com/fluhus/goat for generating go code in my 
>>> projects. I hope it can help you too. It's a minimal tool that takes a 
>>> text/template  template as input, 
>>> runs it on the given parameters and gofmt's the output. You can also use it 
>>> on non-go-source.
>>> Feedback is welcome.
>>>
>>> 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...@googlegroups.com.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/golang-nuts/406179d9-c8f5-497d-8832-ea04ff9d03b3n%40googlegroups.com
>>  
>> 
>> .
>>
>
>
> -- 
> 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/978ebadf-81a6-4375-841b-ee6e15b537c5n%40googlegroups.com.


Re: [go-nuts] Re: Generating go code using go templates

2021-09-20 Thread Vasiliy Tolstov
I'm writing a code generator from protobuf via templates and i can say -
debugging it is very hard. When you have big files you can't check syntax
easily, don't know how it looks and if you have errors in the template it
is really hard to fix them.
So the protoc-gen-go case is preferable.

вс, 19 сент. 2021 г. в 04:33, Denis Cheremisov :

> Templates is the worst approach to code generation IMO. Take a look how
> they do this in protoc-gen-go:
>
> https://github.com/protocolbuffers/protobuf-go/blob/b92717ecb630d4a4824b372bf98c729d87311a4d/cmd/protoc-gen-go/internal_gengo/main.go#L83
>
> I am using very similar approach, albeit I prefer format lines, it looks
> like:
> [image: Screenshot from 2021-09-19 04-22-26.png]
>
> Templates may be OK only in trivial cases. Once you need something less
> trivial it is getting harder and harder to reason how the final code will
> look like with them
> and you will end up with bunch of hard to manage templates. Unlike it,
> line-by-line code generation keep staying close to the final code.
> вторник, 7 сентября 2021 г. в 22:53:51 UTC+3, amitl...@gmail.com:
>
>>
>> Hi gophers,
>> I wrote https://github.com/fluhus/goat for generating go code in my
>> projects. I hope it can help you too. It's a minimal tool that takes a
>> text/template  template as input, runs
>> it on the given parameters and gofmt's the output. You can also use it on
>> non-go-source.
>> Feedback is welcome.
>>
>> 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/406179d9-c8f5-497d-8832-ea04ff9d03b3n%40googlegroups.com
> 
> .
>


-- 
Vasiliy Tolstov,
e-mail: v.tols...@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/CACaajQuOEDr0zyLeS8%3Dm9Xiy1AU12YkqoMtzVkVueaJmbXQ8XA%40mail.gmail.com.


[go-nuts] Re: setuid root

2021-09-20 Thread Rich
Thanks -- that worked.

On Monday, September 20, 2021 at 2:11:21 PM UTC-4 Tamás Gulácsi wrote:

> 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/9a3d069a-dcb4-41fe-8ab7-ae5c7141e5e1n%40googlegroups.com.


[go-nuts] Re: setuid root

2021-09-20 Thread Rich
OK -=- My mistake.  When you setuid a program it sets the user to the owner 
of the file. So I owned the file, so it would run as me. When I did a chown 
root myapplication -- it runs like it should. Thanks everyone for the help.

On Monday, September 20, 2021 at 1:54:33 PM UTC-4 Rich wrote:

> 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/192b7b23-8eed-4397-a5e3-16a63f91b2afn%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 Rich
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/f381480a-0c62-46d4-b739-de7c07d182ffn%40googlegroups.com.


[go-nuts] [ANN] Encore v0.17 is out — The fastest way to build Go backends

2021-09-20 Thread ean...@gmail.com
Hey everyone, we've just released Encore v0.17 
! For those who 
don't know, Encore is an open-source Go framework for building cloud 
backends and distributed systems. It's the most productive way of getting 
your backend application developed and deployed to the cloud (we support 
any of the major cloud providers: GCP, AWS, and Azure).

*What's New in v0.17*

   - Built in support for REST APIs 
   
   - ORM and Query Helper 
    
   support
   - Authentication  improvements
   - Lots of bugfixes


*Encore key features*

   - 
   
   *No Boilerplate :* Set 
   up a production ready backend application in minutes. Define services, API 
   endpoints, and call APIs with a single line of Go code.
   - 
   
   *Databases Made Simple :* Define 
   the schema and then start querying. Encore takes care of provisioning, 
   migrations, connections and passwords.
   - 
   
   *Distributed Tracing :* Your 
   application is automatically instrumented for excellent observability. 
   Automatically capture information about API calls, goroutines, HTTP 
   requests, database queries, and more. Works for both local development and 
   production.
   - 
   
   *Infrastructure Provisioning :* Encore 
   understands how your application works, and provisions and manages your 
   cloud infrastructure. Works with all the major cloud providers using your 
   own account (AWS/Azure/GCP) and for local development.
   - 
   
   *Preview Environments :* Every 
   pull request becomes an isolated test environment. Collaborate and iterate 
   faster than ever.
   - 
   
   *Simple Secrets :* It's never 
   been this easy to store and securely use secrets and API keys. Define 
   secrets in your code like any other variable, Encore takes care of the rest.
   - 
   
   *API Documentation :* Encore 
   parses your source code to understand the request/response schemas for all 
   your APIs, and automatically generates high-quality, interactive API 
   Documentation for you.
   - 
   
   *Generate Frontend Clients 
   :* Automatically 
   generate type-safe, documented clients for your frontends.
   
You can see the complete change log over at GitHub 
. Let us know 
what you think!

— André, on behalf of the Encore contributors

-- 
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/be43b61f-3547-4299-8c9e-030d632e6e3fn%40googlegroups.com.


[go-nuts] Named results allocated on stack instead of register?

2021-09-20 Thread tapi...@gmail.com
Sometimes, a function with named results is slower.
For example: https://play.golang.org/p/wvWkfSRqDLr

The generated directives are almost the same for the two
functions with a named and unnamed result, except one difference.
For the function with the named result, the result represents as "".ret
in the generated directive, but for the function with the unnamed result,
the result represents as "".~r1 in the generated directive.

Does "".ret means the result is allocated on stack? 


-- 
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/4a9bb90a-02d2-42c9-836c-38b411a8bc7cn%40googlegroups.com.


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

2021-09-20 Thread Ian Lance Taylor
On Mon, Sep 20, 2021 at 9:20 AM Glen Newton  wrote:
>
> The maximum size for any single embedded file as []byte is 4GB. What is the 
> total maximum size for all embedded files included this way in a Go binary?
> Also, are there any platform dependencies?

The total maximum size for all embedded files depends on what the
platform is able to support.  And, yes, there are platform
dependencies.  Most 32-bit platforms can't support a total size larger
than 2G.  Most 64-bit platforms have much larger limits, though I
don't know specifically what they are offhand.

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/CAOyqgcXp0HtYWn3%3D52Etj-KVO%2BMYNDMZ1VXBPS7XB_xM3ywUMA%40mail.gmail.com.


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

2021-09-20 Thread Glen Newton
Hello,

The maximum size for any single embedded file as []byte is 4GB. What is the 
total maximum size for all embedded files included this way in a Go binary?
Also, are there any platform dependencies?

Thanks,
Glen

-- 
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/ab0e928c-fb52-44ff-b242-718c99da819fn%40googlegroups.com.


[go-nuts] Re: setuid root

2021-09-20 Thread Brian Candler
Try:
cmd:=exec.Command("id")

If it's definitely running as root then it could be other system-level 
restrictions: SELinux for example.  If so, "dmesg" output may give you a 
clue, logging the policy violation.

On Monday, 20 September 2021 at 16:20:39 UTC+1 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/4984a142-96c7-4d8e-af19-e30c7f039ee1n%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] setuid root

2021-09-20 Thread Rich
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/b1986275-0129-40d7-88c1-a71419834341n%40googlegroups.com.