is there any way to get Windows User name using golang?
I would like to get a Domain too. In my case Domain is "WORKGROUP"
cmd -> systeminfo:
You must us os and os/user packages to handle domain and current username
package main
import (
"fmt"
"os"
"os/user"
)
func main() {
fmt.Println(user.Current()) //return current username
fmt.Println(os.Hostname()) //return the hostname(domain)
}
user.Current() returns the user currently running the application. It does NOT return the currently logged in user for which you will need to use the WTS functions of the windows package of golang ("golang.org/x/sys/windows") and retrieve session details of the currently active session.
Related
package common
import (
"github.com/dgrijalva/jwt-go"
)
type Claims struct {
UserId uint
jwt.StandardClaims
}
Above is my code. Today, after using the gin and gorm framework normally, I created a new jwt.go file in the common package. When I run the main function, golang prompts an error (undefined: jwt) in the last line, but in the go.mod file, I am prompted that I have downloaded "github. com/dgrijalva/jwt-go".
I tried to get github.com/dgrijalva/jwt-go and import go get - u github.com/golang-jwt/jwt again, but neither of the two methods worked
I am fairly new to the Go programming language and completely new to the Go SDK from AWS. I am trying to use a service but I have a strange problem where the types defined by the imported service are found, but the functions of the service are undefined.
This question is not about using the particular service, but just how to correctly import it. My code:
package auth
import (
"log"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/cognitoidentityprovider"
)
func SignUpTest() {
input := cognitoidentityprovider.SignUpInput{
Username: aws.String("example#mail.com"),
Password: aws.String("test1234"),
}
_, err := cognitoidentityprovider.SignUp(&input)
if err != nil {
log.Fatal(err)
}
}
I get the following error when running go build:
auth/signup.go:18:12: undefined: cognitoidentityprovider.SignUp
The autocomplete in my IDE also states that it can find the cognitoidentityprovider.SingUpInput struct, but it is unable to find the cognitoidentityprovider.SignUp function.
I use Go 1.10.1 on WSL Ubuntu. I use DEP 0.4.1 for package management. I verified that the AWS SDK is available in the vendor folder and that the cognitoidentityprovider package is available (the SignUp) function is also there.
What am I missing here?
The error says it all. cognitoidentityprovider.SignUp isn't defined, because there is no symbol SignUp exported by the cognitoidentityprovider package.
I'm not really sure what you want to do instead, since I'm not familiar with that SDK, but you're trying to call a function that doesn't exist. I suggest re-examining the documentation or example you're following. You've probably made a simple mistake.
You seem to be confused by the CognitoIdentityProvider.SignUp instance method. But as that's an instance method, and not an exported function, it requires an instance of a CognitoIdentityProvider first:
cip := cognitoidentityprovider.New( ... )
_, err := cip.SignUp(input)
How can i access the device system in gomobile?
Is there a way to interact with the native libs?
Like this:
package xy
import(
"Foundation"// ios libraray
)
// Do some stuff with the Foundation package
func Test(){
}
Yes. Take a look at Reverse Bindings here; https://godoc.org/golang.org/x/mobile/cmd/gobind
To summarise, you import the Android/ObjectiveC library and are good to go.
The example they give;
import "ObjC/Foundation/NSDate
d := NSDate.Date()
I followed creating a basic web app with go, I created the folder with name myApp. In myApp have main.go and public folder(in public have index.html), here is my content in main.go:
package main
import "net/http"
import "github.com/russross/blackfriday"
func main() {
http.HandleFunc("/markdown", GenerateMarkdown)
http.Handle("/", http.FileServer(http.Dir("public")))
http.ListenAndServe(":8080", nil)
}
func GenerateMarkdown(rw http.ResponseWriter, r *http.Request) {
markdown := blackfriday.MarkdownCommon([]byte(r.FormValue("body")))
rw.Write(markdown)
}
I started server and go to http://localhost:8080/ but it doesn't link to index.html. Can anyone explain why it doesn't render index.html file. I'm a newbie in Golang.
This was answered in the comments, so here is a summary for completeness or something.
The code presented in the question produced the expected results after the actual build->run->test->repeat process was clarified for OP. Points of clarification were as follows:
After using go build to compile the binary, the program isn't running yet. Be sure to actually execute the binary before trying to connect to the server.
If it's necessary to make changes, stop the server, run go build again, then run the new binary.
As a side note, gin is a tool that tries to automate this process by rebuilding and launching your program each time you save the file.
Me and a few friends are writing a server using golang (revel) and had a database implemented just a few weeks ago. Then suddenly everything just stopped working and the go compiler can't find my import files. That includes EmptyPlugin as well as RegisterPlugin.
We are all pretty new so this is probably a pretty simple fix. I have checked my github.com/robfig/revel folder, and there is no file called EmptyPlugin. But that is probably a misunderstanding from my side :P.
By commenting the lines revel.EmptyPlugin and revel.RegisterPlugin(DbPlugin{}) everything works as it should.
package controllers
import (
"database/sql"
"fmt"
_ "github.com/bmizerany/pq"
"github.com/robfig/revel"
"log"
"time"
//"strconv"
)
type DbPlugin struct {
revel.EmptyPlugin
}
func init() {
revel.RegisterPlugin(DbPlugin{})
}
var db *sql.DB
var err error
You appear to compiling using the latest and recently updated version of Revel: https://github.com/robfig/revel.
However, it appears that your code was written for this older version of Revel: https://github.com/robfig/revel/tree/dev.
Update your code to the latest version of Revel.