[go-nuts] Best method for getting input from user?
Hello again, I was wondering in y'all's opinion the best method for getting information from the user. I am gonna create a licensing system and need to be able to let the user add credentials to the specified local json map database, as well as remove credentials. They also must be able to start the server on a specified port and be able to stop it. I thought having a GUI would be the best possible way to achieve this but this project must be cross platform and having a GUI that uses cgo really isn't cross platform. You probably saw my thread asking for this! Suggestions appreciated, 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. For more options, visit https://groups.google.com/d/optout.
[go-nuts] Re: I am confused.
A 9 yo shouldn't be online talking to adult strangers, it's irresponsible for whoever is in charge of that group to let that thread open, let alone let a 9 y.o. in this group when the internet is full of child predators. Le lundi 28 mai 2018 02:31:42 UTC+2, John a écrit : > > Okay I will confess my age: 9 .. > > On Saturday, May 26, 2018 at 9:07:26 PM UTC-7, alex@gmail.com wrote: >> >> Have you not seen my post about joining a chat server? >> Instead of waiting a day or so for each reply, people could reply >> instantly and hold your hand through setting things up. >> >> On Sunday, 27 May 2018 11:37:48 UTC+8, John wrote: >>> >>> Well I guess I would just use the Go playground so it is easier. >>> >>> >>> On Saturday, May 26, 2018 at 8:27:59 PM UTC-7, John wrote: I tried to find the terminal button but did not find it. And also I don't know but does the welcome screen say welcome using or something. Because I can't find the blue vertical line on the right. But to make matters worse Okay I confess: I am just a kid under 15, and me and my mom just moved to CA two years ago. And because of that she do not know much English so our computer is installed from a language that is nothing alike English. When I downloaded VS code it is in that language, and I don't know how to get it to English. But the good thing is I have good proper English. On Thursday, May 24, 2018 at 8:18:21 AM UTC-7, buc...@gmail.com wrote: > > When you open VS Code there is a welcome screen. On the left side of > the screen you open/create a program filename to work on. Note the BLUE > vertical line separating the narrow left window from the larger right > window where you do your program editing. Toward the bottom of that > window > you'll see another BLUE horizontal line. Below that BLUE line click on > the > "Terminal" and to the right of that you'll see the word "1: powershell" > and > below those you'll see the intro to Windows Powershell and a command line > prompt. cd to the directory where the file you are working on is located. > > Thereafter, as you go along writing your program in the upper window, > you can drop down into the lower command line window periodically and you > can type 'go build yourfilename.go' and the go compiler will attempt to > compile your program, showing you any errors it hits along the way. If > it > doesn't hit any errors, the command line will return. If it shows > errors, > return to the upper window and fix them (the errors will usually show the > line number that had the error). > > Open a Windows command window elsewhere (on another monitor), cd to > the same directory you are in in the VS Code lower window and execute the > command, observing the output. Go back-and-forth between the VS Code IDE > and the command window to change your program to get the results you want. > > Go on and accomplish great things! I have no computer science > background, am not particularly smart, am a noob to Go and am able to > write > a complex web server application with Go that does exactly what I want. > You can, too. Persistence! There are lots of free, .pdf books online > that > teach you Go programming. > > (notice my liberal use of the word 'Go') > > > On Wednesday, May 23, 2018 at 11:04:38 PM UTC-6, John wrote: >> >> Yes I did, what do you mean by top part of the screen? >> >> >> On Wednesday, May 23, 2018 at 6:54:47 AM UTC-7, buc...@gmail.com >> wrote: >>> >>> Did you get Go installed? >>> -- 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. For more options, visit https://groups.google.com/d/optout.
Re: [go-nuts] Automatically re-run the golang file when the file is running, then the error
ok Thank you!... I will try now... On Monday, May 28, 2018 at 6:20:58 PM UTC+7, Rohit Jain wrote: > > You have to use defer and recover in your `main` function if you are not > specifically handling the individual error > > > ``` > > > // recover must always be used in defer call > // because when panic occurs , all defer functions are called before > function returns > // https://blog.golang.org/defer-panic-and-recover > defer func() { > r := recover() > if r == nil { > return > } > //err = errors.Errorf("panic: %s", r) > // call your function again here > }() > > ``` > > > On Monday, May 28, 2018, Seven Dang> wrote: > >> Help me..! >> >> ex: >> >> trap1.go >> trap2.go >> main.go >> >> -> run file : go run trap1.go , go run trap2.go >> >> When running, the internet connection is down or the data connection is >> down. I want the files that are corrupt to automatically run again. >> >> The best way to write a command for main.go is to run the file again >> >> trên window và linux >> >> >> 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...@googlegroups.com . >> For more options, visit https://groups.google.com/d/optout. >> > > > -- > Rohit Jain > > -- 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. For more options, visit https://groups.google.com/d/optout.
Re: [go-nuts] Cross platform native(no dependencies) GUI options.
I just do not like the slow compile speeds and the inability to cross compile easily. It just sucks to have a language with such power and to have a libraries kill it. Thanks for the comment though! -- 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. For more options, visit https://groups.google.com/d/optout.
[go-nuts] Re: Cross platform native(no dependencies) GUI options.
I'm not certain that blocking CGO because of compile speed should be a primary concern. The package that implements the interface to the underlying system should be built once and installed. After that, the impact on build speed should be no different than importing any other package. Unfortunately, I don't have any measurements. The second reason to avoid CGO is the difficulty of building on windows. However, if you only need to access DLLs, all FFI calls can be made using the syscall package, so CGO is not needed. Robert On Sunday, 27 May 2018 16:51:32 UTC-4, ati...@mail.ccsf.edu wrote: > > Hello, > > I would like you guys to suggest some GUI libraries that do not have any > HTML/CSS or C bindings, are cross platform and require no dependencies. > > When I say native, I mean no dependencies. I do not mean native to the OS. > This would be great but I don't see any available that have no C bindings. > I understand that to create a native to the OS experience there must be > calls to the OS API which in most cases use the C language. > > Before anyone asks why I do not want C bindings, it is because they do not > have good cross compilation support or good compile speeds. > > Suggestions appreciated, Thanks so much! > -- 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. For more options, visit https://groups.google.com/d/optout.
Re: [go-nuts] Re: Counting semaphore vs Workerpool
There is also a hybrid model: Model A: for each work item, create a goroutine. This is easy to program, but uses additional resources for the goroutines. Model B: keep a worker pool and feed a channel. This bounds the goroutine count and requires more code to pull off and make correct. I'm going to propose Model C. Keep work in an array. Spawn 500 goroutines and have them try to take a message on a chan which acts like a counting semaphore. They each mark work in the array as being processed. Every once in a while, spawn a new set of 500 goroutines and let them have the new work. If they manage to get a message from the semaphore, they operate, otherwise they terminate. This bounds the goroutine count, but it avoids having to explicitly manage a worker pool. If your work is stored persistently on disk, Model C can be pretty alluring since you can have something like CREATE INDEX todo_idx ON Work(processed) WHERE processed = false; CREATE INDEX progress_idx ON Work(in_progress) WHERE in_progress = false; in an SQL database and then you do: SELECT W.id FROM Work W WHERE processed = false AND in_progress = false LIMIT 500; Due to the partial indexes, this is fast. And if each worker marks something as in_progress, you avoid additional work. Basically, you have a bucket of work and make sure it is full of water once in a while. Also, if you drip-feed into the counting semaphore you've just built a system which is also able to load regulate. It isn't like one model is particularly better than the other. It all depends on what kind of problem you are trying to solve and what kind of failure semantics you want your system to have. In particular, I've found that you need to focus on the failure semantics first in a system[0] [0] This is also the major reason why errors should be treated as values over control operators in most cases. On Sat, May 26, 2018 at 6:52 PMwrote: > So, it looks to me like 1 million URLS will spin up 1 million goroutines. > That seems unnecessary, and likely to be a problem. I usually default to > the simplest model, unless there is a reason to do otherwise. IMHO, here > that would be to spin up as many goroutines as you want to be working at > once (500), then feed data through a channel. Untested pseudo-code: > func fetchAll(ctx context.Context) { > workerCount := min(500, len(urls)) > c := make(chan string) > > // Spin up workers > for i := 0; i < workerCount; i++ { > go doWork(ctx, c) > } > // Feed them work > > for _, u := range urls { > > if u == "" { > continue > > } > _, err := url.Parse(u) > if err != nil { > log.Printf("%s returned an error- %v", u, err) > continue > } > > c <- u > } > // All work sent, signal workers to die. Note, workers may still be > // processing at this point. > close(c) > } > > func doWork(ctx context.Context, c chan string) { > for { > u := <-c > if u == "" { > // channel was closed ... no more work. > return > } > fetch(ctx, u) > } > } > > func fetch(ctx context.Context, u string) { > > req, err := http.NewRequest(http.MethodGet, u, nil) > if err != nil { > log.Printf("%s returned an error while creating a request- %v", u, > err) > return > } > req = req.WithContext(ctx) > res, err := http.DefaultClient.Do(req) > if err != nil { > log.Printf("%s returned an error while performing a request - %v" > , u, err) > return > } > //Close response body as soon as function returns to prevent resource > > //leakage. https://golang.org/pkg/net/http/#Response > defer res.Body.Close() > } > > I find this basic model simple and easy top reason about. And it should > avoid wasted goroutines. I have not really paid much attention to "fetch". > I assume it was already correct code. I'm not sure if you are expecting to > handle a cancel on the Context. If so, then you will want to add a check > for that in your main fetchAll() loop, and bail early if it was canceled. > > > On Saturday, May 26, 2018 at 11:48:28 AM UTC-4, Karthik Rao wrote: >> >> I am writing an application that has to fetch data from - say a million >> URLs. I currently have an implementation which looks like the code below >> >> //Make sure that we just have 500 or less goroutines fetching from URLs >> sem := make(chan struct{}, min(500, len(urls))) >> //Check if all URLs in the request are valid and if so spawn a goroutine >> to fetch data. >> for _, u := range urls { >> _, err := url.Parse(u) >> if err != nil { >> log.Printf("%s returned an error- %v", u, err) >> continue >> } >> go fetch(ctx, sem, u) >> } >> >> func fetch(ctx context.Context, sem chan struct{}, u string) { >> sem <- struct{}{} >> defer func() { <-sem }() >> req, err := http.NewRequest(http.MethodGet, u, nil) >> if err != nil { >>
Re: [go-nuts] Automatically re-run the golang file when the file is running, then the error
You have to use defer and recover in your `main` function if you are not specifically handling the individual error ``` // recover must always be used in defer call // because when panic occurs , all defer functions are called before function returns // https://blog.golang.org/defer-panic-and-recover defer func() { r := recover() if r == nil { return } //err = errors.Errorf("panic: %s", r) // call your function again here }() ``` On Monday, May 28, 2018, Seven Dangwrote: > Help me..! > > ex: > > trap1.go > trap2.go > main.go > > -> run file : go run trap1.go , go run trap2.go > > When running, the internet connection is down or the data connection is > down. I want the files that are corrupt to automatically run again. > > The best way to write a command for main.go is to run the file again > > trên window và linux > > > 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. > For more options, visit https://groups.google.com/d/optout. > -- Rohit Jain -- 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. For more options, visit https://groups.google.com/d/optout.
Re: [go-nuts] Re: I am confused.
On Sun, 27 May 2018 17:47:36 -0700 (PDT) alex.rou...@gmail.com wrote: > Then you shouldn't even have a google account/gmail and shouldn't be > posting on google groups. OP: At least unless your Mom is sitting beside you and you are just assisting her in her use ofaccount ;) Seriously - someone should help this kid get a GSE account address. [ GSE: https://support.google.com/a/answer/139019 ] > The only legit way for you to have a google account would be for your > parents to manage it for you, which I highly doubt is the case. > https://support.google.com/families/answer/7101025 Good advice to him. I bet he will be able to help his mom set up a FamilyLink to his address ;) I am so glad that as a 7yo kid I wasn't barred from "student's" library and as 11yo kid I had been given access to all libraries in my town including university / university of technology ones... -- 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. For more options, visit https://groups.google.com/d/optout.
Re: [go-nuts] Re: I am confused.
On Sun, 27 May 2018 17:31:42 -0700 (PDT) Johnwrote: > Okay I will confess my age: 9 .. So your age is a major obstacle for many adults willing to help you set up in programming field. In many countries an adult speaking to a kid over the net can be in legal trouble. Don't be angry at them, or upset. This is written in the law to protect kids less self-aware than you. Still there are options to get you on the fast lane to learn anything you want. 1. Khan Academy https://www.khanacademy.org/ provides teaching at all levels. As far as I know they do not discriminate on age. 2. CODE.org https://code.org/ specializes in teaching computer science. Kids and schoolteachers alike. 3. https://www.ck12.org/student/ will provide you with many textbooks. 4. https://yourbasic.org/golang/ is a portal to many Go focused readings. Many articles there aimed at way older than you students, but you will understand more and more with the time. As for Go setup: start with playground for a while. Uninstall IDE you installed. It is daunting and has a thousand knobs that for now will only distract you. Go compiler and other tools are easy to use with fingers only. 1. Install git. (This is a source control utility that is used for 'go get'). https://github.com/git-for-windows/git/releases/download/v2.17.0.windows.1/Git-2.17.0-64-bit.exe 2. Install Go tools: https://dl.google.com/go/go1.10.2.windows-amd64.msi You will use it for compiling your programs locally. You will use it on the 3. "Command prompt" aka "console": you can read how to get to it at https://www.howtogeek.com/235101/10-ways-to-open-the-command-prompt-in-windows-10/ 4. Use go playground http://play.golang.org/ as your editor and linter for exercises. Then copy/paste your code into the local editor and save as myprog.go or like and compile. After some time you will be confident enough to write all code locally, I bet. The most basic "programmer's" editor is called Notepad++ https://notepad-plus-plus.org/repository/6.x/6.9.2/npp.6.9.2.Installer.exe If you are brave enough you may also learn vim editor: https://ftp.nluug.nl/pub/vim/pc/gvim81.exe I respect you, your sincerity and your will to learn young man. Keep on! Hope this helps, -- Wojciech S. Czarnecki << ^oo^ >> OHIR-RIPE P.S. I urge someone with Windows environment to write a followup explaining step-by-step WIndows specific ways (set up GOPATH mkdir/cd on console). I am not familiar with win console enough and I do not want to mislead OP with nix/mac 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. For more options, visit https://groups.google.com/d/optout.
[go-nuts] Automatically re-run the golang file when the file is running, then the error
Help me..! ex: trap1.go trap2.go main.go -> run file : go run trap1.go , go run trap2.go When running, the internet connection is down or the data connection is down. I want the files that are corrupt to automatically run again. The best way to write a command for main.go is to run the file again trên window và linux 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. For more options, visit https://groups.google.com/d/optout.