goestoeleven / golangtraining Goto Github PK
View Code? Open in Web Editor NEWTraining for Golang (go language)
License: Other
Training for Golang (go language)
License: Other
Hey Todd,
Great stuff on these Udemy vids and code, I'm learning a lot. One thing I noticed however was the code here uses a Sleep in main() to wait for the goroutines to finish. I'm fine with using Sleep for testing deadlocks and race conditions but I modified this to not used a Sleep and use either a WaitGroup or boolean channel semaphores. Ran into issues and couldn't understand with such a simple example why trying to implement these schemes failed and the Sleep would work. Finally realized the goroutine in the infinite loop just dies when the main thread is finished by the end of the Sleep.
I've attached a txt file of the main.go file since I can't attach *.go types. It's got code for using for loop or channel range and WaitGroup or semaphores. One thing I did find out while testing and not sure if you mentioned this in your videos or not but if you used a channel range YOU MUST EXPLICITLY CLOSE THE CHANNEL or it will hang at the range loop.
Somewhere I read that the channels don't consume system resources like a network connection or a file open so unless they are being consumed through a channel/range loop it's not always necessary to handle closing them, they just get eligible for garbage collection when going out of scope and having no references.
Hopefully, this makes sense and may provide a little cleaner implementation should someone else try to do what I did.
Thanks,
Howard
Problem Description : There is dll( A1.dll- compiled in C++) in which a function is defined as
EXPORT void S3(HWND hwnd, HINSTANCE hinst, LPSTR lpszCmdLine, int nCmdShow){}
A1.dll
`// dllmain.cpp : Defines the entry point for the DLL application.
#include "pch.h"
#include
//#include
#define EXPORT extern "C" __declspec(dllexport)
EXPORT void S3(HWND hwnd, HINSTANCE hinst, LPSTR lpszCmdLine, int nCmdShow)
{
MessageBox(NULL, TEXT("Hello World"),
TEXT("In a DLL"), MB_OK);
}
**I want to load this DLL using GO lang. For this I am writing below program:**package main
import (
"fmt"
"syscall"
"golang.org/x/sys/windows"
)
func main() {
dll, err := syscall.LoadDLL("A1.dll")
proc, err := dll.FindProc("S3")
_, _, dllError := proc.Call()
fmt.Println("calling S3")
fmt.Printf("Error, err: %s\n", dllError)
fmt.Printf("Error, err: %s\n", err)
}`
This is not working. Also I am not able to understand that here how to pass the parameter in call function according to function S3 definition. Could anybody help me in understanding this issue?
I notice this doesn't show a race condition in your videos. Any idea? My guess is the -race became more sensitive since the video was made? The code produces the correct counter number, so I'm wondering if we would consider this a 'false positive' on the part of the compiler...
After printing the string program panics and terminate.
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x40 pc=0x11eb2f0]
goroutine 1 [running]:
main.main()
<path>/main.go:21 +0x160
package main
import (
"fmt"
)
func main() {
in := gen()
out := make(chan int)
// FAN OUT
// Multiple functions reading from the same channel until that channel is closed
// Distribute work across multiple functions (ten goroutines) that all read from in.
fanOut(in, 10, out)
// FAN IN
// multiplex multiple channels onto a single channel
// merge the channels from c0 through c9 onto a single channel
go func() {
for v := range out {
fmt.Println(v)
}
}()
var a string
fmt.Scanln(&a)
}
func gen() <-chan int {
out := make(chan int)
go func() {
for i := 0; i < 10; i++ {
for j := 3; j < 13; j++ {
out <- j
}
}
close(out)
}()
return out
}
func fanOut(in <-chan int, n int, out chan<- int) {
for i := 0; i < n; i++ {
factorial(in, out)
}
}
func factorial(in <-chan int, out chan<- int) {
go func() {
for n := range in {
out <- fact(n)
}
}()
}
func fact(n int) int {
total := 1
for i := n; i > 0; i-- {
total *= i
}
return total
}
This is just a suggestion...
Instead of doing this all the time:
if err!=nil{
panic(err);
}
why not make a function...
func check(e error){
if e!=nil{
panic(e)
}
}
Im asking this since i dont exactly know how to make a pull request..
How to use the REPL mode in the Golang language?
The Google Cloud API client libraries for Go are making some breaking changes:
google.golang.org/cloud/...
tocloud.google.com/go/...
. For example, if your code imports the BigQuery clientimport "google.golang.org/cloud/bigquery"
import "cloud.google.com/go/bigquery"
google.golang.org/cloud
togoogle.golang.org/api/option
. Two have also been renamed:
WithBaseGRPC
is now WithGRPCConn
WithBaseHTTP
is now WithHTTPClient
cloud.WithContext
and cloud.NewContext
methods are gone, as are theClient
You should make these changes before September 12, 2016, when the packages at
google.golang.org/cloud
will go away.
can't load package: package github.com/GoesToEleven/GolangTraining: no Go files in go/src/github.com/GoesToEleven/GolangTraining
Without the go.mod an IDE would show errors in a file where modules are used, e.g. 02_package/main/main.go. Why not add a go.mod with just one line?
module github.com/GoesToEleven/GolangTraining
A readme seems like the bare minimum.
I want to learn go, can some give me some suggest?
"github.com/GoesToEleven/GolangTraining/47_templates/04_template_csv-parse/parse"
"github.com/GoesToEleven/GolangTraining/56_twitter/18_abstract-API-Model/api"
"github.com/GoesToEleven/GolangTraining/56_twitter/19_abstract-API-Model_AE-fix/Model"
"github.com/GoesToEleven/GolangTraining/56_twitter/19_abstract-API-Model_AE-fix/API"
"github.com/GoesToEleven/GolangTraining/56_twitter/19_abstract-API-Model_AE-fix/Memcache"
With Go 1.6 RC1 including vendor support without needing to set an extra environmental variable, I believe the concepts of vendoring should be introduced, as well as some demos with a popular go vendor tool like https://github.com/kardianos/govendor
Using a vendor tool flattens the dependency tree to a single level and allows for cleaner and more reliable code.
I want to know if the project is still under maintenance. If there is still maintenance, I would like to submit some Chinese comments for the code.
I want to add the effect of CSS file in GO code. HTML is added to it. Can somebody say how to add CSS file.
I want to design a webpage using Go using HTML script. But I am quite unsure whether to use the HTML script directly to the Go source code or whether create a index.html in the similar directory. Can someone help me out with this.
import "fmt' direcly lose when i save it
Todd,
In the changeMe function of 04_string-pointer/main.go, you seem to be using the memory allocation for a string of 4 characters ("Todd") to store a string of 5 characters ("Rocky").
Wouldn't the changeMe function be causing memory corruption issues?
Thanks!
fmt.Println(z) // 0x82023c080 fmt.Println(*z) // Todd *z = "Rocky" fmt.Println(z) // 0x82023c080 fmt.Println(*z) // Rocky
the path 21_interfaces/04_method-sets/04_pointer-receiver_value-type/main.go coding is error
Fam pic.md
👋 Hello, we've received a report for a potential critical severity security issue in your repository.
1️⃣ Visit https://huntr.dev/bounties/1-other-GoesToEleven/GolangTraining for more advisory information.
2️⃣ Sign-up to validate or speak to the researcher for more assistance.
3️⃣ Propose a patch or outsource it to our community.
Join us on our Discord and a member of our team will be happy to help! 🤗
Speak to a member of our team: @JamieSlome
This issue was automatically generated by huntr.dev - a bug bounty board for securing open source code.
I am using centos 7.
[puneets@server1]~/MyWork/experiments/exp2>export GOPATH=$PWD/
[puneets@server1]~/MyWork/experiments/exp2>ls
[puneets@server1]~/MyWork/experiments/exp2>
[puneets@server1]~/MyWork/experiments/exp2>
[puneets@server1]~/MyWork/experiments/exp2>mkdir bin src pkg
[puneets@server1]~/MyWork/experiments/exp2>ls
bin pkg src
[puneets@server1]~/MyWork/experiments/exp2>go get -d github.com/GoesToEleven/GolangTraining/...
go: go.mod file not found in current directory or any parent directory.
'go get' is no longer supported outside a module.
To build and install a command, use 'go install' with a version,
like 'go install example.com/cmd@latest'
For more information, see https://golang.org/doc/go-get-install-deprecation
or run 'go help get' or 'go help install'.
[puneets@server1]~/MyWork/experiments/exp2>go mod init github.com/test
go: creating new go.mod: module github.com/test
go: to add module requirements and sums:
go mod tidy
[puneets@server1]~/MyWork/experiments/exp2>go get -d github.com/GoesToEleven/GolangTraining/...
$GOPATH/go.mod exists but should not
Why GO is not allowing me download course material in workspace?
Did i miss anything here?
Is there a way to download course material in $PWD or $GOPATH ?
How to use the REPL mode in the Golang language
"io/ioutil" is deprecated: As of Go 1.16, the same functionality is now provided by package [io] or package [os], and those implementations should be preferred in new code.
Hi
I made this patch to ajust 59_appengine-GCS-storage/02_NewWriter_JSON-auth code with the new storage package update. More details here: Storage Package Update.
Best regards, Gustavo Bittencourt.
diff --git a/59_appengine-GCS-storage/02_NewWriter_JSON-auth/storage.go b/59_appengine-GCS-storage/02_NewWriter_JSON-auth/storage.go
index e42e737..77d1cc3 100755
--- a/59_appengine-GCS-storage/02_NewWriter_JSON-auth/storage.go
+++ b/59_appengine-GCS-storage/02_NewWriter_JSON-auth/storage.go
@@ -6,10 +6,8 @@ import (
"golang.org/x/oauth2/google"
- "golang.org/x/net/context"
"golang.org/x/oauth2/jwt"
"google.golang.org/appengine"
- "google.golang.org/cloud"
"google.golang.org/cloud/storage"
"io/ioutil"
)
@@ -37,21 +35,16 @@ func init() {
}
-func getCloudContext(req *http.Request) (context.Context, error) {
- ctx := appengine.NewContext(req)
- hc := conf.Client(ctx)
- return cloud.NewContext(aeId, hc), nil
-}
-
func handlePut(res http.ResponseWriter, req *http.Request) {
- cctx, err := getCloudContext(req)
+ ctx := appengine.NewContext(req)
+ client, err := storage.NewClient(ctx)
if err != nil {
- http.Error(res, "ERROR GETTING CCTX: "+err.Error(), 500)
+ http.Error(res, "ERROR CREATING NEW CLIENT: "+err.Error(), 500)
return
}
-
- writer := storage.NewWriter(cctx, gcsBucket, "myOffice.txt")
+ bucketHandle := client.Bucket(gcsBucket)
+ writer := bucketHandle.Object("myOffice.txt").NewWriter(ctx)
writer.ContentType = "text/plain"
io.WriteString(writer, "in my office")
err = writer.Close()
@@ -59,4 +52,5 @@ func handlePut(res http.ResponseWriter, req *http.Request) {
http.Error(res, "ERROR WRITING TO BUCKET: "+err.Error(), 500)
return
}
+ client.Close()
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.