Giter VIP home page Giter VIP logo

golangtraining's Introduction

GolangTraining

Training for Golang (go language)

golangtraining's People

Contributors

007jasonsmith avatar devotiongeo avatar gbitten avatar goestoeleven avatar saxleader avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

golangtraining's Issues

update Google Cloud API client import paths and more

The Google Cloud API client libraries for Go are making some breaking changes:

  • The import paths are changing from google.golang.org/cloud/... to
    cloud.google.com/go/.... For example, if your code imports the BigQuery client
    it currently reads
    import "google.golang.org/cloud/bigquery"
    It should be changed to
    import "cloud.google.com/go/bigquery"
  • Client options are also moving, from google.golang.org/cloud to
    google.golang.org/api/option. Two have also been renamed:
    • WithBaseGRPC is now WithGRPCConn
    • WithBaseHTTP is now WithHTTPClient
  • The cloud.WithContext and cloud.NewContext methods are gone, as are the
    deprecated pubsub and container functions that required them. Use the Client
    methods of these packages instead.

You should make these changes before September 12, 2016, when the packages at
google.golang.org/cloud will go away.

Error Handling #2

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..

Add go vendor

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.

unable to download course material in GOPATH

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 ?

ADDING CSS FILE IN GO

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.

Potential Security Issue

👋 Hello, we've received a report for a potential critical severity security issue in your repository.

Next Steps

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.


Confused or need more help?

  • 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.

fmt

import "fmt' direcly lose when i save it

HOW TO USE HTML WITH GO

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.

Potential memory corruption with 14_functions/15_passing-by-value/04_string-pointer/main.go

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

Infinite loop - 22_go-routines/09_channels/00_unbuffered-channels-block

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

main.txt

Issue in calling a function from DLL in GO Lang

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?

Another approach...

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
}

Cannot find list of packages

"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"

Why not add go.mod?

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

Patch for 59_appengine-GCS-storage/02_NewWriter_JSON-auth

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()
 }

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.