[go-nuts] When doing "type X Y", is it a type alias or type redefinition or type adapter or something else?

2019-08-12 Thread Sathish VJ
And what is the difference between each of these: type alias, type 
redefinition, type adapter.

-- 
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/ffafebcc-b8e9-4aa2-bb8d-e9dd2efc8f54%40googlegroups.com.


[go-nuts] [gccgo] weird constant values in sysinfo.go

2019-08-12 Thread Xiangdong JI
Hello,

The .go files generated during building gccgo seem to have a few constants 
with weird values, for example:

// sysinfo.go (on x86-64, latest gcc-9 trunk)

const ___FLT128_MAX__ = 1.1
const ___FLT32X_DENORM_MIN__ = 1.1

as a comparison, gollvm generates expected values.
Could it be caused by incorrect building setting? 
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/b808ccdd-023c-4b95-9db0-2a00b3435735%40googlegroups.com.


[go-nuts] how cgo handle user define signal ? need go pass the signal handle to c

2019-08-12 Thread hui zhang
I am trying to extend a old c program with go.Add websocket ability to 
this c program.
first  build  go as a  .so  dynamic lib
then link the so lib in c program
I run the cgo ok in an example program.
But when integrate with old c program,  c program will send a signal 42 to 
itself periodly. 
this cause so lib terminate 

rogram received signal SIG42, Real-time event 42.
[Switching to Thread 0xa53c6b70 (LWP 14957)]
runtime.futex () at /usr/local/go/src/runtime/sys_linux_386.s:444
444 /usr/local/go/src/runtime/sys_linux_386.s: No such file or directory.
in /usr/local/go/src/runtime/sys_linux_386.s
Missing separate debuginfos, use: debuginfo-install WBXcms-3.7.0-494.i686
(gdb) bt
#0 runtime.futex () at /usr/local/go/src/runtime/sys_linux_386.s:444
#1 0xb7b04c2a in runtime.futexsleep (addr=0xb7fa47ac, val=0, ns=-1) at 
/usr/local/go/src/runtime/os_linux.go:46
#2 0xb7ae5437 in runtime.notesleep (n=0xb7fa47ac) at 
/usr/local/go/src/runtime/lock_futex.go:151
#3 0xb7b0c8f4 in runtime.stopm () at /usr/local/go/src/runtime/proc.go:1936
#4 0xb7b0d848 in runtime.findrunnable (gp=@0x74421300, inheritTime=@0x0) at 
/usr/local/go/src/runtime/proc.go:2399
#5 0xb7b0e507 in runtime.schedule () at 
/usr/local/go/src/runtime/proc.go:2525
#6 0xb7b0edac in runtime.goexit0 (gp=0x744000e0) at 
/usr/local/go/src/runtime/proc.go:2722
#7 0xb7b2f868 in runtime.mcall () at /usr/local/go/src/runtime/asm_386.s:345
#8 0xb7b2f7c0 in runtime.rt0_go () at 
/usr/local/go/src/runtime/asm_386.s:241
#9 0xb7b2f7c7 in runtime.rt0_go () at 
/usr/local/go/src/runtime/asm_386.s:246
#10 0x00

My question is 
*how go so lib ignore this signal 42,  and pass the signal handle to old c 
program.*

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/22745e49-1d43-4e3a-9d78-20ff6bb20d4e%40googlegroups.com.


Re: [go-nuts] JSON Marshal for config file url encoding string.

2019-08-12 Thread Rich
Thanks!! Totally missed that one. Switched to from json.Marshal to 
json.Encode:
jsonEnc:=json.NewEncoder(file)
jsonEnc.SetIndent("", tab)
jsonEnc.SetEscapeHTML(false) 

Works great!!


On Monday, August 12, 2019 at 2:18:02 PM UTC-4, Jesper Louis Andersen wrote:
>
> Documented here: https://golang.org/pkg/encoding/json/#Marshal
>
> There is also a description of how to avoid it.
>
> On Mon, Aug 12, 2019 at 7:39 PM Rich > 
> wrote:
>
>> Hi I have an application that I wrote that uses JSON for the config file. 
>> The application is a chatbot I use internally and allows users to run linux 
>> commands to get information both locally and via ssh. The chatbot interface 
>> uses basic html to render the output so 90% of the time I want to have the 
>> output be surrounded by "" and "". But not every one running the 
>> application may want this, their chatbot may run a commands that that uses 
>> other HTML formatting. So I created a directive in the config file allowing 
>> the user to configure this:
>>
>> "HTMLFormat": {
>> "Start": "",
>> "Finish": ""
>> }
>>
>> The problem is that this config file also contains a password -- so I 
>> allow the user to put in clear text the password, and on restart the 
>> password gets encrypted, and then I do a simple json.Marshal and rewrite 
>> the config with the encrypted password:
>>
>> file, err := json.MarshalIndent(config, "", "   ")
>> errorHandle(err, "Json Marshal", false)
>> err = ioutil.WriteFile(cFile, file, 0644)
>> errorHandle(err, "Write Config", false)
>>
>> In the above, 'config' is the struct that contains all the directive, 
>> 'cFile' is the config file being written.  When the file gets written it 
>> looks like this:
>>  has toIn the json there is a directive for the application to add html 
>> formatting to the start of its output.
>>
>> "HTMLFormat": {
>> "Start": "\u003cpre\u003e",
>> "Finish": "\u003e\/pre\u003e"
>> }
>>
>> Any idea why it's doing 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 golan...@googlegroups.com .
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/golang-nuts/8a7a344a-55aa-468a-8346-c1db036d8372%40googlegroups.com
>>  
>> 
>> .
>>
>
>
> -- 
> J.
>

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


Re: [go-nuts] JSON Marshal for config file url encoding string.

2019-08-12 Thread Jesper Louis Andersen
Documented here: https://golang.org/pkg/encoding/json/#Marshal

There is also a description of how to avoid it.

On Mon, Aug 12, 2019 at 7:39 PM Rich  wrote:

> Hi I have an application that I wrote that uses JSON for the config file.
> The application is a chatbot I use internally and allows users to run linux
> commands to get information both locally and via ssh. The chatbot interface
> uses basic html to render the output so 90% of the time I want to have the
> output be surrounded by "" and "". But not every one running the
> application may want this, their chatbot may run a commands that that uses
> other HTML formatting. So I created a directive in the config file allowing
> the user to configure this:
>
> "HTMLFormat": {
> "Start": "",
> "Finish": ""
> }
>
> The problem is that this config file also contains a password -- so I
> allow the user to put in clear text the password, and on restart the
> password gets encrypted, and then I do a simple json.Marshal and rewrite
> the config with the encrypted password:
>
> file, err := json.MarshalIndent(config, "", "   ")
> errorHandle(err, "Json Marshal", false)
> err = ioutil.WriteFile(cFile, file, 0644)
> errorHandle(err, "Write Config", false)
>
> In the above, 'config' is the struct that contains all the directive,
> 'cFile' is the config file being written.  When the file gets written it
> looks like this:
>  has toIn the json there is a directive for the application to add html
> formatting to the start of its output.
>
> "HTMLFormat": {
> "Start": "\u003cpre\u003e",
> "Finish": "\u003e\/pre\u003e"
> }
>
> Any idea why it's doing 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/8a7a344a-55aa-468a-8346-c1db036d8372%40googlegroups.com
> 
> .
>


-- 
J.

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


[go-nuts] JSON Marshal for config file url encoding string.

2019-08-12 Thread Rich
Hi I have an application that I wrote that uses JSON for the config file. 
The application is a chatbot I use internally and allows users to run linux 
commands to get information both locally and via ssh. The chatbot interface 
uses basic html to render the output so 90% of the time I want to have the 
output be surrounded by "" and "". But not every one running the 
application may want this, their chatbot may run a commands that that uses 
other HTML formatting. So I created a directive in the config file allowing 
the user to configure this:

"HTMLFormat": {
"Start": "",
"Finish": ""
}

The problem is that this config file also contains a password -- so I allow 
the user to put in clear text the password, and on restart the password 
gets encrypted, and then I do a simple json.Marshal and rewrite the config 
with the encrypted password:

file, err := json.MarshalIndent(config, "", "   ")
errorHandle(err, "Json Marshal", false)
err = ioutil.WriteFile(cFile, file, 0644)
errorHandle(err, "Write Config", false)

In the above, 'config' is the struct that contains all the directive, 
'cFile' is the config file being written.  When the file gets written it 
looks like this:
 has toIn the json there is a directive for the application to add html 
formatting to the start of its output.

"HTMLFormat": {
"Start": "\u003cpre\u003e",
"Finish": "\u003e\/pre\u003e"
}

Any idea why it's doing 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/8a7a344a-55aa-468a-8346-c1db036d8372%40googlegroups.com.


[go-nuts] How to auto generate function code hidden .go files for static library built by -buildmode=archive?

2019-08-12 Thread nifflerfox
When I publish a Go package which need to hide important code
 

> go build -buildmode=archive -o ***.a


I use this command to make .a static library, when other users need to use 
this .a static library, they need this .a and .go files which have all 
needed public functions, structs and constants definition, like this:



package libdemo
> function MyBusinessAlgorithmFunc(in string) (string) { return ""}



Now this is my question, how to generate function code hidden .go files 
like this? I don't hope to write them by hand, there are a large amount of 
functions in my 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/af65f789-60ff-49b0-aeba-db88092af2ca%40googlegroups.com.


Re: [go-nuts] I know you cannot kill a goroutine, but ...

2019-08-12 Thread 'Jim Idle' via golang-nuts
Good luck on your implementation. I suggest though that you will find too
many issues like this to use go routines as the base model for a user. I
looked in to threads as a model for jBASE and even with that model, it was
going to be too fraught with difficulty. Unless you are considering a
production grade implementation with 1000's of users, then I would just
implement it as separate go processes. You don't have to use shared memory
unless you are trying to copy Universe, but even if you did, you can still
use such things in go (though mmap might a better way).

Your bigger problem, if you are trying to provide a complete copy, is
reproducing the query language and conversion processor. with all their
quirks and strangeness. The compiler is easy compared to that :)

Jim

On Sat, Aug 10, 2019 at 2:34 AM  wrote:

> Background:
> UniVerse is a Pick model, multivalue database,
> https://groups.google.com/forum/#!forum/mvdbms for some general
> information.
> Multivalue databases permit more than one value in a column for a row.
> Since you do not know the size of the column with hundreds or thousands of
> values in the column-row, you do not know the size of the record. Access
> dictates linked lists to handle variability in record size. So, every row
> gets a unique primary key and stored in hash tables with an appropriately
> large number of hash buckets for the data - key / value pairs. With good
> hashing, I can often access a record in a single disk access. Group (hash
> table bucket) locking happens within the environment, while users request
> row locking. Each user in UniVerse is a separate O/S process. Locking
> activity occurs in shared memory, using assembly test-and-set kinds of
> instructions or host-specific semaphores.
>
> After retiring, I decided it would be a fun experiment to build a
> clean-room implementation of UniVerse. Go does not do interprocess
> communication at the rate that would match the shared memory semaphore
> activity in UniVerse. A natural match implements each user as a goroutine.
> UniVerse provides an extended BASIC language for accessing and manipulating
> table data that runs close to the engine. In a language you can do silly
> things like create an infinite loop. In a production environment of 1000s
> of users, you cannot simply bounce the environment because one user is
> eating a CPU. An admin function to dismiss or kill a goroutine would be
> ideal. Not possible in the current Go world.
>
> For an infinite loop to exist, you need to branch "backwards" or call a
> routine that calls you back with some possible indirection. (An equivalent
> in Go is "for {}" with no break. Here, you would not get back to the
> traditional mechanism of telling a goroutine to shut down where one of the
> channels for select is the shutdown indicator.)  There may be other
> examples I have yet to think of. When I "compile" BASIC, I can put checks
> into those two functions, call, and branch (to a lower address), without
> inducing too much overhead. an unimportant detail is that the BASIC
> compiles to a p-code run on a run machine, comparable to a JVM. I might
> even be able to find the PC, Program Counter or IA, Instruction Address,
> and insert some kind of trap instruction opcode, that would cause it to try
> the select statement and see the shutdown channel. But in the general case,
> this may be insufficient. I think a "context" timeout would interrupt a
> properly long-running program in a way that might be hard to restart if
> shutdown was not requested.
>
> As a database, there is also the possibility of deadly embrace. Killing
> one of the two (or more) goroutines in a deadly embrace would be useful.
> This normally occurs on poorly managed acquisition of exclusive locks on
> database table rows. I could forcibly release a lock, but then would need
> extra work so that a user goroutine that thinks it exclusively owns a lock,
> finds that it does not, and would need to gracefully exit or handle the
> situation.
>
> As a goroutine, each user does not have a STDIN, and STDOUT to communicate
> with its user. Currently, the user communicates with the goroutine with a
> socket connection. I can probably redesign, adding a new goroutine
> accepting user requests/commands on a channel, and monitoring the shutdown
> channel with a select in a loop. Otherwise, I could not get a goroutine to
> shut down if it is waiting on user input from a socket, or a dropped
> connection, although that begs the question of how to get the
> socket-reading goroutine to now shut down.
>
> The current Go implementation smells of cooperative multitasking. Not a
> bad thing, per se, but makes it hard to stop in certain degenerate cases.
> Have I missed a way to deal with some of the discussed issues?
>
> The project has certainly been a good way to become familiar with a number
> of the Go idioms. (BTW, I happen to *like* the current way of handling
> errors!)
>
> --
> You received this message because 

[go-nuts] Any tool can auto generate fake go files with type definition for binary-only-package?

2019-08-12 Thread nifflerfox
I don't want to write type definition for fake go files, but type 
definition is necessary for binary-only-package end users, like code hint. 
If the package has a lot of functions/structs, write type definition is an 
impossible hard 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/84d09002-fa81-487d-a9fa-b6a0ba3a396d%40googlegroups.com.


Re: [go-nuts] Wrapper package for dialog (and Xdialog)?

2019-08-12 Thread Wojciech S. Czarnecki
On Sun, 11 Aug 2019 06:17:53 -0700 (PDT)
Tong Sun  wrote:

> I know there are several ncurses based wrapper packages (like goncurses), 
> but are there any wrapper packages out there dialog (and Xdialog), or 
> something similar? The goncurses is still too low-level for my 
> simple dialog-base requirement/use. 

You can try to embed tcl/tk, the standard unix way for doing dialog with x-user.

[recent]
https://github.com/visualfc/atk

[ooold]
https://github.com/nsf/gothic

Hope this helps,

-- 
Wojciech S. Czarnecki
 << ^oo^ >> OHIR-RIPE

-- 
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/20190812145206.646bbeb6%40zuzia.


[go-nuts] Re: How to propagate multiple errors using the new fmt.Errorf wrapping

2019-08-12 Thread anderson . queiroz
Hi Alex,

I see your problem is more like merging errors rather than wrapping them. 
Indeed I don't see any way you could merge 2 errors with the new `
*fmt.Errorf*`

I believe what you want is something which could hold 2 errors, like

type myError struct {
msg string // some additional msg
current error // Layer1Error
cause error // Layer2Error
}

but in that case, you are handling it by yourself, instead of delegating it 
to fmt.Errorf.

What I see as a possibility would be something like:

var (
Layer1Error= errors.New("some error on layer 1: %w")
Layer2Error= errors.New("some error on layer 2")
)

func callLayer1Function() error {
err := callLayer2Function()

// how to not lose layer2 error but also append a new layer1 error ?
// this does not work, since you fully lose layer1 error
// with pkg/err
return fmt.Errorf(Layer1Error.Error(), Layer1Error)
}


However it makes pointles to have `Layer1Error` as an error, it can be juts 
a string.

Best,

Anderson

On Friday, 9 August 2019 15:39:24 UTC+2, Alex wrote:
>
> Sorry, mixed things up in the code with layer1 and layer2... 
>
>
> var (
> Layer1Error= errors.New("some error on layer 1")
> Layer2Error= errors.New("some error on layer 2")
> )
>
> func main() {
> err := callLayer1Function()
>
> // do something with error
> }
>
> func callLayer1Function() error {
> err := callLayer2Function()
>
> // how to not lose layer2 error but also append a new layer1 error ?
> // this does not work, since you fully lose layer1 error
> // with pkg/err
> return fmt.Errorf("some specific layer 1 error message: %w", Layer1Error)
> }
>
> func callLayer2Function() error {
> // wrap an error of Layer2 here
> return fmt.Errorf("some specific layer2 error message: %w", Layer2Error)
> }
>
>
>

-- 
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/08858872-57b1-45a0-86f9-5339a10592fb%40googlegroups.com.