go安装iris失败, package github.com/kataras/iris: exit status 128

今天想安装个iris框架,执行命令行:go get -u -v github.com/kataras/iris

后就卡住了, 过了好久命令行提示如下:

PS C:\Users\dewff> go get -u github.com\kataras\iris
# cd .; git clone https://github.com/kataras/iris D:\go_workspace\src\github.com\kataras\iris
Cloning into 'D:\go_workspace\src\github.com\kataras\iris'...
fatal: early EOF
fatal: The remote end hung up unexpectedly
fatal: index-pack failed
error: RPC failed; curl 18 transfer closed with outstanding read data remaining
package github.com/kataras/iris: exit status 128

我的git环境变量也配了,再任意目录下都可执行git --version


Csdn user default icon
golang:“去获取github.com/ ..”错误,“找不到头文件”-在哪里配置?

<div class="post-text" itemprop="text"> <p>I am trying to use GO with SFML and in a sample program. I need to install package gosfml using "go get".<br> I am on Mac OSX.</p> <p>I have SFML compiled and installed SFML from source. The include files are under /usr/local/include/SFML </p> <p>The following command gives the error of a header file not being found.</p> <pre><code>&gt; go get github.com/manyminds/gosfml # github.com/manyminds/gosfml go-proj/src/github.com/manyminds/gosfml/circleShape.go:7:11: fatal error: 'SFML/Graphics/CircleShape.h' file not found #include &lt;SFML/Graphics/CircleShape.h&gt; ^ 1 error generated. </code></pre> <p>How can I configure GO to find the header file?</p> <p>Thanks (new to Go)</p> </div>


<div class="post-text" itemprop="text"> <p>I use Go: Install/Update Tools in VSCode to install <code>gocode</code> and <code>godef</code> but I get this error :</p> <blockquote> <p>Installing github.com/stamblerre/gocode FAILED Installing github.com/rogpeppe/godef FAILED</p> </blockquote> <p>and in the output -&gt;</p> <blockquote> <p>""D:\Krittawat\Learn\GoWorkspace\src\github.com\stamblerre\gocode" is not using a known version control system" and ""D:\Krittawat\Learn\GoWorkspace\src\github.com\stamblerre\gocode" is not using a known version control system"</p> </blockquote> <p>I check my GOPATH GOROOT GOBIN by using "go env" and this is my GOPATH GOROOT and GOBIN</p> <pre><code>set GOPATH=D:\Krittawat\Learn\GoWorkspace set GOROOT=D:\Krittawat\Programs\go1.12.7.windows-amd64\go set GOBIN= </code></pre> <p>I don't know how to solve it. I searching for solutions, but nothing works.</p> </div>


<div class="post-text" itemprop="text"> <p>I just ran into issues where I am writing small web service with Go Iris framework. Iris has few useful packages for HTTP request error handling.</p> <p>Namely, I wanted to use <strong><em>"github.com/kataras/iris/middleware/logger"</em></strong> and <strong><em>"github.com/kataras/iris/middleware/recover"</em></strong> however when I start typing app.Use(logger....) VSCode auto imported "<strong><em>github.com/hashicorp/consul/logger</em></strong>" which is also in my path. </p> <p>Simply copy-pasting right path will solve the issue, but is there a way to force VSCode to make a manual choice where multiple packages names are matched or even fully disable goimports for these cases.</p> <p>Example below: </p> <pre><code>package main import ( // "github.com/hashicorp/consul/logger" ! incorrect package "github.com/kataras/iris" "github.com/kataras/iris/middleware/logger" "github.com/kataras/iris/middleware/recover" ) func main() { app := iris.New() app.Logger().SetLevel("debug") // Optionally, add 2 built'n handlers // that can recover from any http-related error // and log the requests in terminal app.Use(recover.New()) app.Use(logger.New()) } </code></pre> </div>

在jwt-go中解析JWT Auth令牌时,密钥的类型无效

<div class="post-text" itemprop="text"> <p>I am setting up security middleware in a GoLang API and seem to have everything set up correctly, but I am getting an error ‘key is of invalid type’. </p> <p>I have confirmed that my Signing algorithm is RS256 and the middleware options are configured @ SigningMethod: jwt.SigningMethodRS256</p> <p>I have a valid token…everything else in the middleware passes. </p> <p>The entry point to this error in the middleware is the jwt.ParseRSAPrivateKeyFromPEM method. </p> <p>I’ve isolated the error down inside the package github.com/dgrijalva/jwt-go/rsa.go Verify() on line :62 is the ErrInvalidKeyType that is getting thrown. All the params up to the this point seem solid and appropriate (eg m|signingString|signature|key) but this key.(*rsa.PublicKey) is failing…in my debugger (GoLand) I inspect *rsa and am given the response ‘could not find symbol value for rsa’…</p> <pre><code>if rsaKey, ok = key.(*rsa.PublicKey); !ok { return ErrInvalidKeyType } </code></pre> <p>please note…if it’s not already too obvious…i’m noob to GoLang</p> <p>----- UPDATE -----</p> <p>So at the most granular level the panic starts at go/1.12.8/libexec/src/crypto/rsa/rsa.go:49 with </p> <pre><code>func (pub *PublicKey) Size() int { log.Printf("SIZE ::: %v :: %v",pub.N.BitLen(), pub.N) return (pub.N.BitLen() + 7) / 8 } </code></pre> <p>The pub is seen as a nil pointer dereference. I trace it back to mux --&gt;</p> <blockquote> <p>crypto/rsa.VerifyPKCS1v15(...) /usr/local/Cellar/go/1.12.8/libexec/src/crypto/rsa/pkcs1v15.go:275</p> <p>github.com/dgrijalva/jwt-go.(*SigningMethodRSA).Verify(...) /Users/me/Sandbox/src/github.com/dgrijalva/jwt-go/rsa.go:73</p> <p>github.com/dgrijalva/jwt-go.(*Parser).ParseWithClaims(...) /Users/me/Sandbox/src/github.com/dgrijalva/jwt-go/parser.go:77</p> <p>github.com/dgrijalva/jwt-go.(*Parser).Parse(...) /Users/btschirhart/Sandbox/src/github.com/dgrijalva/jwt-go/parser.go:20</p> <p>github.com/dgrijalva/jwt-go.Parse(...) /Users/me/Sandbox/src/github.com/dgrijalva/jwt-go/token.go:89</p> <p>github.com/auth0/go-jwt-middleware.(*JWTMiddleware).CheckJWT(...) /Users/me/Sandbox/src/github.com/auth0/go-jwt-middleware/jwtmiddleware.go:203</p> <p>github.com/auth0/go-jwt-middleware.(*JWTMiddleware).Handler.func1(...) /Users/me/Sandbox/src/github.com/auth0/go-jwt-middleware/jwtmiddleware.go:110</p> <p>net/http.HandlerFunc.ServeHTTP(...) /usr/local/Cellar/go/1.12.8/libexec/src/net/http/server.go:1995</p> <p>github.com/gorilla/mux.(*Router).ServeHTTP(...) /Users/me/Sandbox/src/github.com/gorilla/mux/mux.go:210 +0xe3</p> </blockquote> </div>


<div class="post-text" itemprop="text"> <p>I'm a nodejs developer and I generally use a structure for my apps which holds a configuration package/object that holds references to my often used libs and configuration options. Generally this configuration object holds my database connections as well and it's reachable trough my application.</p> <p>I tried to build similar to this in go and failed horribly. </p> <p>My plan was to build a public variable which holds a reference for my config struct. But when I try to call my <code>Config.Database</code> I get this panic:</p> <pre><code>2017/02/19 14:05:44 http: panic serving runtime error: invalid memory address or nil pointer dereference goroutine 50 [running]: net/http.(*conn).serve.func1(0xc42027c000) /usr/local/go/src/net/http/server.go:1491 +0x12a panic(0x9f45c0, 0xc42000c100) /usr/local/go/src/runtime/panic.go:458 +0x243 main.SignUp(0xc4202780e0) /home/attila/dev/gopath/src/github.com/attilasatan/helloiris/handlers.go:31 +0x258 github.com/kataras/iris.HandlerFunc.Serve(0xafaf00, 0xc4202780e0) /home/attila/dev/gopath/src/github.com/kataras/iris/http.go:211 +0x30 github.com/kataras/iris.(*Context).Do(0xc4202780e0) /home/attila/dev/gopath/src/github.com/kataras/iris/context.go:152 +0x4d github.com/kataras/iris.(*serveMux).BuildHandler.func1(0xc4202780e0) /home/attila/dev/gopath/src/github.com/kataras/iris/http.go:1059 +0x6ea github.com/kataras/iris.(*Framework).Build.func1.1(0xd87e20, 0xc4202701a0, 0xc420284000) /home/attila/dev/gopath/src/github.com/kataras/iris/iris.go:411 +0x72 net/http.HandlerFunc.ServeHTTP(0xc420235080, 0xd87e20, 0xc4202701a0, 0xc420284000) /usr/local/go/src/net/http/server.go:1726 +0x44 net/http.serverHandler.ServeHTTP(0xc420089f80, 0xd87e20, 0xc4202701a0, 0xc420284000) /usr/local/go/src/net/http/server.go:2202 +0x7d net/http.(*conn).serve(0xc42027c000, 0xd88820, 0xc42015c200) /usr/local/go/src/net/http/server.go:1579 +0x4b7 created by net/http.(*Server).Serve /usr/local/go/src/net/http/server.go:2293 +0x44d 2017/02/19 14:05:44 http: panic serving runtime error: invalid memory address or nil pointer dereference goroutine 51 [running]: net/http.(*conn).serve.func1(0xc42027c180) /usr/local/go/src/net/http/server.go:1491 +0x12a panic(0x9f45c0, 0xc42000c100) /usr/local/go/src/runtime/panic.go:458 +0x243 main.SignUp(0xc4202ac070) /home/attila/dev/gopath/src/github.com/attilasatan/helloiris/handlers.go:31 +0x258 github.com/kataras/iris.HandlerFunc.Serve(0xafaf00, 0xc4202ac070) /home/attila/dev/gopath/src/github.com/kataras/iris/http.go:211 +0x30 github.com/kataras/iris.(*Context).Do(0xc4202ac070) /home/attila/dev/gopath/src/github.com/kataras/iris/context.go:152 +0x4d github.com/kataras/iris.(*serveMux).BuildHandler.func1(0xc4202ac070) /home/attila/dev/gopath/src/github.com/kataras/iris/http.go:1059 +0x6ea github.com/kataras/iris.(*Framework).Build.func1.1(0xd87e20, 0xc4202a60d0, 0xc4202840f0) /home/attila/dev/gopath/src/github.com/kataras/iris/iris.go:411 +0x72 net/http.HandlerFunc.ServeHTTP(0xc420235080, 0xd87e20, 0xc4202a60d0, 0xc4202840f0) /usr/local/go/src/net/http/server.go:1726 +0x44 net/http.serverHandler.ServeHTTP(0xc420089f80, 0xd87e20, 0xc4202a60d0, 0xc4202840f0) /usr/local/go/src/net/http/server.go:2202 +0x7d net/http.(*conn).serve(0xc42027c180, 0xd88820, 0xc42015c480) /usr/local/go/src/net/http/server.go:1579 +0x4b7 created by net/http.(*Server).Serve </code></pre> <p>Here is my configure file. As you can see I'm using <code>tideland/golib/redis</code> for redis connection.</p> <p><strong>configure.go</strong></p> <pre><code>package main import ( "fmt" "strconv" "time" "github.com/tideland/golib/redis" ) /*Configuration is the main type of app configuration */ type Configuration struct { Database *redis.Connection } /*Config is app configuration holder */ var Config *Configuration /*Configure handles database connection */ func Configure() (*Configuration, error) { db, err := redis.Open(redis.TcpConnection("", 30*time.Second)) if err != nil { fmt.Printf("Database connection error") return nil, err } conn, err := db.Connection() n, _ := conn.DoInt("INCR", "IDIDID") fmt.Printf(strconv.Itoa(n)) if err != nil { fmt.Printf("Database connection error") return nil, err } /*Config is the main configuration object*/ Config := &amp;Configuration{conn} return Config, err } </code></pre> <p>And here is where I use <code>Config.Database</code>. </p> <p><strong>handlers.go</strong></p> <pre><code>func SignUp(ctx *iris.Context) { mail := ctx.FormValue("email") password := ctx.FormValue("password") passwordConfirm := ctx.FormValue("password-confirm") if password != passwordConfirm { ctx.RenderWithStatus(iris.StatusBadRequest, "400.html", ErrorPageData{"passwords dont match"}) } else { user := User{mail, password, 0} db := Config.Database userID, err := db.DoInt("INCR", "HELLOIRIS:ID") if err != nil { ctx.RenderWithStatus(iris.StatusBadRequest, "400.html", ErrorPageData{"passwords dont match"}) } else { user.ID = userID fmt.Printf("SAVED") ctx.Render("signup-success.html", nil) } ctx.JSON(200, user) } } </code></pre> <p>After this fail I changed <code>Configure</code> function like this:</p> <p><strong>configure.go</strong></p> <pre><code>func Configure() (Config *Configuration, err error) { if Config != nil { return } } </code></pre> <p>and I changed the usage at handler </p> <p><strong>handlers.go</strong></p> <pre><code>config, err := Configure() if err != nil { ctx.RenderWithStatus(iris.StatusBadRequest, "400.html", ErrorPageData{"try again later"}) return } user := User{mail, password, 0} db := config.Database </code></pre> <p>... and everything start to work perfectly.</p> <p>My problem is I simply don't understand why... Why did I get this panic when I use a public pointer and why didn't I get when I returned the same pointer from a function?</p> </div>

使用“ dep”管理项目依赖项时未安装iris的“ hero”组件

<div class="post-text" itemprop="text"> <p>this question also posted here: <a href="https://github.com/kataras/iris/issues/1081" rel="nofollow noreferrer">https://github.com/kataras/iris/issues/1081</a></p> <p>I am using "iris" as the MVC framework in my golang project, and i use "dep" to manage the dependencies of my project. </p> <p>the "iris" dependency was configured in "Gopkg.toml" as bellow:</p> <p><a href="https://i.stack.imgur.com/WJHKX.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/WJHKX.png" alt="enter image description here"></a></p> <p><a href="https://i.stack.imgur.com/wEBxS.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/wEBxS.png" alt="enter image description here"></a></p> <p>and later i use "dep ensure -v" to download all the dependencies.</p> <p>after the "ensure" command finished, i check the downloaded files in "vendor/github.com/kataras/iris/hero" folder, i found there is no source code files were downloaded, refer to the screen capture bellow:</p> <p><a href="https://i.stack.imgur.com/xEOS7.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/xEOS7.png" alt="enter image description here"></a></p> <p>so i cannot use "hero" component in my project, because the "hero" related package not installed in my project.</p> <p><a href="https://i.stack.imgur.com/yaC0H.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/yaC0H.png" alt="enter image description here"></a></p> <p>thanks all for your help ~</p> </div>


<div class="post-text" itemprop="text"> <p>This is my code </p> <pre><code>`package main import "github.com/kataras/iris" func main() { iris.Get("/hi", func(ctx *iris.Context) { ctx.Writef("Hi %s", "iris") }) iris.Listen(":8080") }` </code></pre> <p>I have "go get -u github.com/kataras/iris/iris" this is what i get, and i've been surving and still cannot solve this.</p> <p>./IRIS.go:6: undefined: iris.Get<br> ./IRIS.go:9: undefined: iris.Listen</p> <p>This is my first time trying this framework, I followed from page <a href="https://docs.iris-go.com/" rel="nofollow noreferrer">https://docs.iris-go.com/</a> I though it would easy, but its really not, i only can do install iris, and this is my first worse hello world</p> <p>I'm using Intellij Idea as my IDE</p> <p>Please Help Me. Thanks</p> </div>


<div class="post-text" itemprop="text"> <p>I'm beginner in go and now want to create a big project my question is where should create connection and where close connection in http requests now i declare db in main function and use in all requests and don't close connection:</p> <pre><code>package main import ( "fmt" "github.com/jinzhu/gorm" "github.com/kataras/iris" "github.com/kataras/iris/context" "github.com/kataras/iris/middleware/recover" _ "github.com/go-sql-driver/mysql" ) var db *gorm.DB func main() { port := "8080" app := iris.New() app.Configure() app.Logger().SetLevel("debug") app.Use(recover.New()) db1, err := gorm.Open("mysql", "root:@/database?charset=utf8&amp;parseTime=True&amp;loc=Local") //db1, err := gorm.Open("mysql", "payro:AEkCpNhd@/payro_db?charset=utf8&amp;parseTime=True&amp;loc=Local") if err != nil { fmt.Println(err.Error()) panic(err) } db=db1 app.Get("/", func(i context.Context) { db.Exec("update tbl1 set col1=''") i.Next() }) app.Get("/test", func(i context.Context) { db.Exec("update tbl2 set col2=''") i.Next() }) _ = app.Run(iris.Addr(":"+port), iris.WithConfiguration(iris.Configuration{ //DisableBodyConsumptionOnUnmarshal:true, }), iris.WithoutServerError(iris.ErrServerClosed)) } </code></pre> <p>this code is ok?</p> </div>

如何通过Iris服务/ api和HTML5 SPA

<div class="post-text" itemprop="text"> <p>I'm trying to get iris (<a href="http://iris-go.com" rel="nofollow">http://iris-go.com</a>) to serve both /api/ routes and host an angular SPA (in html5 mode). </p> <p></p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false"> <div class="snippet-code"> <pre class="snippet-code-js lang-js prettyprint-override"><code>package main import ( "github.com/kataras/iris" // "github.com/kataras/iris/utils" // "strings" ) func allVendorBrandLabel(c *iris.Context) { c.WriteString("Hello, api :)") } func main() { iris.Get("/api/all", allVendorBrandLabel) iris.StaticWeb("/", "./www", 2) iris.Listen(":8080") }</code></pre> </div> </div> <p>Can't get this approach to work. Has anyone gotten iris to do this?</p> </div>


<div class="post-text" itemprop="text"> <p>I'm a newer to Go and Iris, and I'm trying to set up an API server. I want to upload a file by CURL for a test. But when i use <code>ctx.FormFile("data")</code> or <code>ctx.UploadFormFile("./uploads")</code> to upload a file, it will returns <code>multipart: NextPart: EOF</code>. How can I solve this problem? Thanks!</p> <p>curl:</p> <pre><code>curl -i -v -F 'data=@\"test.txt\"' "http://localhost:8080/upload_file" </code></pre> <p>main.go:</p> <pre><code>package main import ( "github.com/kataras/iris" "github.com/kataras/iris/middleware/logger" "github.com/kataras/iris/middleware/recover" "github.com/kataras/iris/mvc" "./controllers" ) func main() { app := iris.New() app.Use(recover.New()) app.Use(logger.New()) filesController := new(controllers.FilesController) filesApp := mvc.New(app) filesApp.Handle(filesController) app.Run(iris.Addr(":8080")) } </code></pre> <p>filesController.go:</p> <pre><code>package controllers import ( "fmt" "github.com/kataras/iris" "github.com/kataras/iris/mvc" ) type FilesController struct {} func (c *FilesController) BeforeActivation(b mvc.BeforeActivation) { middleware := func(ctx iris.Context) { ctx.Application().Logger() ctx.Next() } b.Handle("POST", "/upload_file", "UploadFile", middleware) } func (c *FilesController) UploadFile(ctx iris.Context) { // ctx.FormFile("data") len, err := ctx.UploadFormFiles("./uploads") fmt.Println(len, err) } </code></pre> <p>execute curl renturns</p> <pre><code>* Expire in 0 ms for 6 (transfer 0x8dd060) * Expire in 1 ms for 1 (transfer 0x8dd060) * Expire in 3 ms for 1 (transfer 0x8dd060) * Expire in 2 ms for 1 (transfer 0x8dd060) * Expire in 7 ms for 1 (transfer 0x8dd060) * Expire in 10 ms for 1 (transfer 0x8dd060) * Expire in 4 ms for 1 (transfer 0x8dd060) * Expire in 15 ms for 1 (transfer 0x8dd060) * Expire in 50 ms for 1 (transfer 0x8dd060) * Expire in 50 ms for 1 (transfer 0x8dd060) * Trying ::1... * TCP_NODELAY set * Expire in 149969 ms for 3 (transfer 0x8dd060) * Expire in 200 ms for 4 (transfer 0x8dd060) * Connected to localhost (::1) port 8080 (#0) &gt; POST /upload_files HTTP/1.1 &gt; Host: localhost:8080 &gt; User-Agent: curl/7.64.0 &gt; Accept: */* &gt; Content-Length: 221 &gt; Content-Type: multipart/form-data; boundary=------------------------7f0a822525 fc9e4c &gt; &lt; HTTP/1.1 200 OK HTTP/1.1 200 OK &lt; Set-Cookie: demo_app_cookie=425c2c0b-852d-49ea-967a-09214bcdec18; Path=/; Expi res=Sun, 12 Jun 2044 03:48:13 GMT; Max-Age=784591442; HttpOnly Set-Cookie: demo_app_cookie=425c2c0b-852d-49ea-967a-09214bcdec18; Path=/; Expire s=Sun, 12 Jun 2044 03:48:13 GMT; Max-Age=784591442; HttpOnly &lt; Date: Fri, 02 Aug 2019 05:44:10 GMT Date: Fri, 02 Aug 2019 05:44:10 GMT &lt; Content-Length: 0 Content-Length: 0 &lt; * Connection #0 to host localhost left intact </code></pre> <p>UploadFile function returns</p> <pre><code>0 multipart: NextPart: EOF [INFO] 2019/08/02 11:49 200 36.002ms ::1 POST /upload_file </code></pre> </div>


<div class="post-text" itemprop="text"> <pre><code>&lt;!-- file: web/views/hello/index.html --&gt; &lt;html&gt; &lt;head&gt; &lt;title&gt;{{.Title}} - My App&lt;/title&gt; &lt;/head&gt; &lt;body&gt; &lt;p&gt;{{.MyMessage}}&lt;/p&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <hr> <pre><code>package main import ( "github.com/kataras/iris" ) func main() { app := iris.New() // Load the template files. app.RegisterView(iris.HTML("./web/views", ".html")) // Serve our controllers. mvc.New(app.Party("/hello")).Handle(new(controllers.HelloController)) // http://localhost:8080/hello app.Run( iris.Addr("localhost:8080"), iris.WithoutVersionChecker, iris.WithoutServerError(iris.ErrServerClosed), iris.WithOptimizations, ) } </code></pre> <hr> <pre><code>package controllers import ( "github.com/kataras/iris/mvc" ) type HelloController struct{} var helloView = mvc.View{ Name: "hello/index.html", Data: map[string]interface{}{ "Title": "Hello Page", //"MyMessage": "Welcome to my awesome website", }, } func (c *HelloController) Get() mvc.Result { return helloView } </code></pre> <p>I want to direct return template html. in func (c *HelloController) Get() mvc.View { return helloView } , but Once I do this , The parameters in the template will be empty. {{.Title}} and {{.MyMessage}} is missing</p> </div>


<div class="post-text" itemprop="text"> <p>I am studying Iris framework recently. I encountered a question when I was implementing the Handler. Like following:</p> <pre class="lang-golang prettyprint-override"><code>package controller import "github.com/kataras/iris" type Pages struct{ } func (p *Pages) Serve(c *iris.Context) { } </code></pre> <p>In order to use this controller, I implemented the following entry script:</p> <pre class="lang-golang prettyprint-override"><code>package main import ( "github.com/kataras/iris" "web/controller" ) func main(){ ctrl := controller.Pages{} iris.Handle("GET", "/", ctrl) iris.Listen(":8080") } </code></pre> <p>But when I compiled the code, I got the following error message:</p> <pre><code>cannot use ctrl (type controllers.Pages) as type iris.Handler in argument to iris.Handle: controllers.Pages does not implement iris.Handler (Serve method has pointer receiver) </code></pre> <p>After I changed the declaration to:</p> <pre><code>ctrl := &amp;controller.Pages{} </code></pre> <p>Then the compiler passed with no complaint. </p> <p>The question is: I thought the following statements are equal, since the GO compiler will do the conversion under the table:</p> <pre class="lang-golang prettyprint-override"><code>type Pages struct { } func (p *Pages) goWithPointer() { fmt.Println("goWithPointer") } func (p Pages) goWithValue() { fmt.Println("goWithValue") } func main() { p1 := Pages{} p2 := &amp;Pages{} p1.goWithPointer() p1.goWithValue() p2.goWithPointer() p2.goWithValue() } </code></pre> <p>Why can't I use <code>ctrl := controller.Pages{}</code> as the parameter to <code>iris.Handle()</code>, instead of <code>ctrl := &amp;controller.Pages{}</code> as the parameter to <code>iris.Handle()</code>?</p> <p>Thank you for your time and sharing.</p> </div>

Go模块:如何锁定不会被`go get -u`覆盖的特定版本?

<div class="post-text" itemprop="text"> <p>If I specify a specific branch/version using <code>go get github.com/org/package@sha_or_branch</code> it will update accordingly. But if I run <code>go get -u</code> afterwards it gets overridden with any newer version. </p> <p>Is there any way to lock it in so it doesn't change when doing a <code>go get -u</code>?</p> </div>

尝试呈现模板,但出现错误html / template:“ templates / index.html”未定义

<div class="post-text" itemprop="text"> <p>I have a simple main.go script that loads a template from a folder. The template looks like:</p> <pre><code>&lt;html&gt; &lt;head&gt; &lt;title&gt;T2 template&lt;/title&gt; &lt;/head&gt; &lt;body&gt; hello &lt;/body&gt; &lt;/html&gt; </code></pre> <p>The main.go script looks is:</p> <pre><code>package main import ( "fmt" "html/template" "log" "net/http" "os" "github.com/gorilla/mux" ) var ( templates = template.Must(template.ParseFiles("templates/index.html")) ) func main() { port := os.Getenv("PORT") fmt.Printf("port is: %v ", port) r := mux.NewRouter() r.HandleFunc("/hello", HomeHandler) log.Fatal(http.ListenAndServe(":"+port, r)) } func HomeHandler(w http.ResponseWriter, r *http.Request) { tmpl := "templates/index.html" err := templates.ExecuteTemplate(w, tmpl, "") if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) } } </code></pre> <p>I'm not sure what is wrong here.</p> <p>The error I see in the browser is:</p> <blockquote> <p>"templates/index.html" is undefined</p> </blockquote> </div>


<div class="post-text" itemprop="text"> <p>I'm new in Golang, I've been doing some code tests to build an REST API using Iris framework, I'm trying to get the body data from a Post to my API but I cannot make it works, I did read the <strong>Body binder</strong> <a href="http://iris-go.com/body_binder/" rel="nofollow">http://iris-go.com/body_binder/</a> and followed the examples. The result I get is an empty structure:</p> <p>My code:</p> <pre><code>package main import ( "github.com/kataras/iris" "fmt" ) type PostAPI struct { *iris.Context } type Lead struct { fbId string email string telefono string version string mac string os string } func (p PostAPI) Post(){ lead := Lead{} err := p.ReadJSON(&amp;lead) if (err != nil) { fmt.Println("Error on reading form: " + err.Error()) return } fmt.Printf("Post! %v", lead) } func main() { iris.API("/", PostAPI{}) iris.Listen(":8080") } </code></pre> <p>The post:</p> <pre><code>curl -H "Content-Type: application/json" -X POST -d '{"fbId": "werwer","email": "werwer@gmail.com","telefono": "5555555555","version": "123","mac": "3j:3j:3j:3j","os": "uno bien chido"}' </code></pre> <p>The result:</p> <pre><code>Post! { } </code></pre> <p>What am I doing wrong?</p> </div>

在Iris Framework中以POST方法重定向

<div class="post-text" itemprop="text"> <p>I'm trying to redirect from the login page to the home page in the POST method, but the form doesn't redirect to any page after clicking on the submit button.</p> <p>I'm using the MVC structure of Iris Framework and the <code>Ctx.Redirect</code> method to redirect to the desired page, but it's not working.</p> <pre><code>// login_controllers.go package controllers import ( "github.com/kataras/iris/mvc" "github.com/kataras/iris" "fmt" ) type LoginFormData struct { Email string Password string } type LoginController struct { mvc.C } func (c *LoginController) Get() mvc.Result { return mvc.View{ Name: "login.html", } } func (c *LoginController) Post() { userLoginData := LoginFormData{} err := c.Ctx.ReadForm(&amp;userLoginData) if err != nil { c.Ctx.StatusCode(iris.StatusInternalServerError) c.Ctx.WriteString(err.Error()) } if userLoginData.Email == "teste@teste.com" &amp;&amp; userLoginData.Password == "123" { c.Ctx.Redirect("/", iris.StatusSeeOther) fmt.Printf("UserInner: %#v", userLoginData) c.Ctx.Writef("UserInner: %#v", userLoginData) } } </code></pre> <p>The form HTML code is:</p> <pre><code>&lt;form class="m-login__form m-form" action="/login" method="post"&gt; &lt;div class="form-group m-form__group"&gt; &lt;input class="form-control m-input" type="text" placeholder="Email" name="Email" autocomplete="off"&gt; &lt;/div&gt; &lt;div class="form-group m-form__group"&gt; &lt;input class="form-control m-input m-login__form-input--last" type="password" placeholder="Password" name="Password"&gt; &lt;/div&gt; &lt;div class="row m-login__form-sub"&gt; &lt;div class="col m--align-left"&gt; &lt;label class="m-checkbox m-checkbox--focus"&gt; &lt;input type="checkbox" name="remember"&gt; Remember me &lt;span&gt;&lt;/span&gt; &lt;/label&gt; &lt;/div&gt; &lt;div class="col m--align-right"&gt; &lt;a href="javascript:;" id="m_login_forget_password" class="m-link"&gt; Forgotten password ? &lt;/a&gt; &lt;/div&gt; &lt;/div&gt; &lt;div class="m-login__form-action"&gt; &lt;button id="m_login_signin_submit" class="btn btn-focus m-btn m-btn--pill m-btn--custom m-btn--air"&gt; Login &lt;/button&gt; &lt;/div&gt; &lt;/form&gt; </code></pre> <p>Isn't possible to redirect in a POST method in Iris Framework/Go?</p> </div>

在$ GOPATH之外进行销售

<div class="post-text" itemprop="text"> <p>I have a project which is built in Node.js/Express.js. I want to start to rewrite this to go/iris framework. I don't want to re-factor everything into my $GOPATH and I want to keep it together my express / go / docker files for this project.</p> <p>I tried to clone iris framework's git repo into a <code>./vendor</code> subfolder, but using <code>import "github.com/kataras/iris"</code> importing nothing.</p> <p>Is there a package manager which is</p> <ul> <li><p>copying and installing packages and all of it's dependencies in <code>my-project/vendor</code> folder <strong>outside $GOPATH</strong></p></li> <li><p>it can update these import packages</p></li> <li><p><code>go run/build/install</code> outside $GOPATH</p></li> <li><p>there's now any new files in $GOPATH <code>src/pkg/bin</code> folder when I working on a project, except this package manager</p></li> <li><p>I can define dependency packages for a project like <code>package.json</code> file for <code>node.js</code></p></li> </ul> <p>Is there a go package manager like that?</p> <p>Edit:</p> <p>Running this with <code>go</code> command is not required.</p> </div>

html / template:“ xxx”是一页的未定义错误,而另一页不是

<div class="post-text" itemprop="text"> <p>again I'm stuck. I've been experimenting with Golang using this <a href="http://sanatgersappa.blogspot.com/2013/11/creating-master-page-for-your-go-web-app.html" rel="nofollow noreferrer">page</a> as a guide for templates to create a master page. I've managed to get the Go server up with my CSS and JS directories all updated correctly but I am only able to load the <code>index.html</code> page and not the <code>about.html</code> page. <a href="https://github.com/jzng89/TLDR-GO" rel="nofollow noreferrer">Github link here</a></p> <p>I have already tried the solutions in <a href="https://stackoverflow.com/questions/52500451/golang-template-is-undefined">here</a> and <a href="https://github.com/kataras/iris/issues/485" rel="nofollow noreferrer">here</a> but no luck, both the about page and index page are in the same directory and share the same header, footer and navigation bar templates. </p> <p>I have also tried parsing files manually with <code>template.Must(template.ParseFiles("header.html", .....</code> and also tried executing with the .html in the name <code>templ.ExecuteTemplate(w, "about.html", &amp;Page{Title: "About TL;DR"})</code> which does not return an error but instead just loads a blank screen. Any help will be greatly appreciated, thank you in advance!</p> <p>File directory:</p> <p><a href="https://i.stack.imgur.com/5vUPx.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/5vUPx.png" alt="File directory structure"></a></p> <p>servermain.go</p> <pre><code>package main import ( "fmt" "html/template" "log" "net/http" "os" "path/filepath" "strings" ) //Page title type Page struct { Title string } //------------------------------Global Variables-------------------------------------// //Compile templates on start var templ = ParseTemplates() //ParseTemplates use for multi directory html parsing func ParseTemplates() *template.Template { t := template.New("Base") err := filepath.Walk("./", func(path string, info os.FileInfo, err error) error { if strings.Contains(path, ".html") { _, err = t.ParseFiles(path) fmt.Println(path) if err != nil { logger.Println(err) fmt.Println(err) } } return err }) if err != nil { panic(err) } return t } //logging var errorlog *os.File var logger *log.Logger //---------------------------------------Page Handlers----------------------------------// //Handler for homepage func homepageHandler(w http.ResponseWriter, r *http.Request) { fmt.Println("Home") err := templ.ExecuteTemplate(w, "index", &amp;Page{Title: "Welcome to TL;DR"}) if err != nil { fmt.Println(err) logger.Println(err) http.Error(w, err.Error(), http.StatusInternalServerError) } } //Handler for about page func aboutHandler(w http.ResponseWriter, r *http.Request) { fmt.Println("About") err := templ.ExecuteTemplate(w, "about", &amp;Page{Title: "About TL;DR"}) if err != nil { fmt.Println(err) logger.Println(err) http.Error(w, err.Error(), http.StatusInternalServerError) } } //Server log to file func init() { errorlog, err := os.OpenFile("serverlog.log", os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666) if err != nil { fmt.Printf("Error opening file: %v", err) os.Exit(1) } log.SetOutput(errorlog) logger = log.New(errorlog, " TDLR : ", log.Lshortfile|log.LstdFlags) } func main() { //--------------------------------------Routers-------------------------------------// http.HandleFunc("/", homepageHandler) http.HandleFunc("/index", homepageHandler) http.HandleFunc("/about", aboutHandler) http.Handle("/static/", http.StripPrefix("/static/", http.FileServer(http.Dir("static")))) //---------------------------------------------------------------------------------// //start server fmt.Println("Starting server on port 9090") logger.Println("Starting server on port 9090") logger.Fatal(http.ListenAndServe(":9090", nil)) } </code></pre> <p>Error page</p> <p><a href="https://i.stack.imgur.com/a3UrG.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/a3UrG.png" alt="Error page"></a></p> <p>Also I noticed no matter what page I load it will always execute the <code>homepageHandler</code> after executing the <code>aboutHandler</code> as can be seen in the console.</p> <p><a href="https://i.stack.imgur.com/Pta00.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Pta00.png" alt="Console result"></a></p> <p><strong>Edit:</strong> Solved 20181215 Improper definition of the <code>about.html</code> template, change to <code>{{define "about"}}</code> solved the problem.</p> </div>


<div class="post-text" itemprop="text"> <p>I'm playing around with the knnclassifier_iris.go example in the golearn examples folder. I replaced the iris dataset with one of my own, and as long as I train my data on some percentage of the data I read in, all functions work fine and I get some output. However, when I clearly mention a training and testing dataset, and then run predict on the test dataset after fitting the training dataset, I get a nil result when I try to print the predictions. I don't know why I'm getting a nil value, so I would really appreciate some help. </p> <p>My code:</p> <pre><code>package main import ( "fmt" "github.com/sjwhitworth/golearn/base" "github.com/sjwhitworth/golearn/evaluation" "github.com/sjwhitworth/golearn/knn" ) func main() { trainData, err := base.ParseCSVToInstances("~/Desktop/churn_train.csv", true) if err != nil { panic(err) } fmt.Println(trainData) testData, err := base.ParseCSVToInstances("~/Desktop/churn_test.csv", false) if err != nil { panic(err) } fmt.Println(trainData) fmt.Println(testData) //Initialises a new KNN classifier cls := knn.NewKnnClassifier("euclidean", 2) cls.Fit(trainData) //Calculates the Euclidean distance and returns the most popular label predictions := cls.Predict(testData) fmt.Println(predictions) //GETTING &lt;NIL&gt; AS OUTPUT // Prints precision/recall metrics confusionMat, err := evaluation.GetConfusionMatrix(testData, predictions) if err != nil { panic(fmt.Sprintf("Unable to get confusion matrix: %s", err.Error())) //ERROR CAUSED HERE DUE TO GETTING &lt;NIL&gt; } fmt.Println(evaluation.GetSummary(confusionMat)) } </code></pre> </div>


感觉全世界营销文都在推Python,但是找不到工作的话,又有哪个机构会站出来给我推荐工作? 笔者冷静分析多方数据,想跟大家说:关于超越老牌霸主Java,过去几年间Python一直都被寄予厚望。但是事实是虽然上升趋势,但是国内环境下,一时间是无法马上就超越Java的,也可以换句话说:超越Java只是时间问题罢。 太嚣张了会Python的人!找工作拿高薪这么简单? https://edu....


大学四年,看课本是不可能一直看课本的了,对于学习,特别是自学,善于搜索网上的一些资源来辅助,还是非常有必要的,下面我就把这几年私藏的各种资源,网站贡献出来给你们。主要有:电子书搜索、实用工具、在线视频学习网站、非视频学习网站、软件下载、面试/求职必备网站。 注意:文中提到的所有资源,文末我都给你整理好了,你们只管拿去,如果觉得不错,转发、分享就是最大的支持了。 一、电子书搜索 对于大部分程序员...


今年,我也32了 ,为了不给大家误导,咨询了猎头、圈内好友,以及年过35岁的几位老程序员……舍了老脸去揭人家伤疤……希望能给大家以帮助,记得帮我点赞哦。 目录: 你以为的人生 一次又一次的伤害 猎头界的真相 如何应对互联网行业的「中年危机」 一、你以为的人生 刚入行时,拿着傲人的工资,想着好好干,以为我们的人生是这样的: 等真到了那一天,你会发现,你的人生很可能是这样的: ...


分享外包的组织架构,盈利模式,亲身经历,以及根据一些外包朋友的反馈,写了这篇文章 ,希望对正在找工作的老铁有所帮助


何来 我,一个双非本科弟弟,有幸在 19 届的秋招中得到前东家华为(以下简称 hw)的赏识,当时秋招签订就业协议,说是入了某 java bg,之后一系列组织架构调整原因等等让人无法理解的神操作,最终毕业前夕,被通知调往其他 bg 做嵌入式开发(纯 C 语言)。 由于已至于校招末尾,之前拿到的其他 offer 又无法再收回,一时感到无力回天,只得默默接受。 毕业后,直接入职开始了嵌入式苦旅,由于从未...


文章目录Java概述何为编程什么是Javajdk1.5之后的三大版本JVM、JRE和JDK的关系什么是跨平台性?原理是什么Java语言有哪些特点什么是字节码?采用字节码的最大好处是什么什么是Java程序的主类?应用程序和小程序的主类有何不同?Java应用程序与小程序之间有那些差别?Java和C++的区别Oracle JDK 和 OpenJDK 的对比基础语法数据类型Java有哪些数据类型switc...


今天下午在朋友圈看到很多人都在发github的羊毛,一时没明白是怎么回事。 后来上百度搜索了一下,原来真有这回事,毕竟资源主义的羊毛不少啊,1000刀刷爆了朋友圈!不知道你们的朋友圈有没有看到类似的消息。 这到底是啥情况? 微软开发者平台GitHub 的一个区块链项目 Handshake ,搞了一个招募新会员的活动,面向GitHub 上前 25万名开发者派送 4,246.99 HNS币,大约价...


前言: 如何悄悄的打开朋友的摄像头,看看她最近过的怎么样,嘿嘿!这次让我带你们来实现这个功能。 注: 这个程序仅限在朋友之间开玩笑,别去搞什么违法的事情哦。 代码 发送邮件 使用python内置的email模块即可完成。导入相应的代码封装为一个send函数,顺便导入需要导入的包 注: 下面的代码有三处要修改的地方,两处写的qq邮箱地址,还有一处写的qq邮箱授权码,不知道qq邮箱授权码的可以去百度一...


一、菱形继承 在介绍虚继承之前介绍一下菱形继承 概念:A作为基类,B和C都继承与A。最后一个类D又继承于B和C,这样形式的继承称为菱形继承 菱形继承的缺点: 数据冗余:在D中会保存两份A的内容 访问不明确(二义性):因为D不知道是以B为中介去访问A还是以C为中介去访问A,因此在访问某些成员的时候会发生二义性 缺点的解决: 数据冗余:通过下面“虚继承”技术来解决(见下) 访问...


一、前言 注意,关于ipv4和ipv6,ipv4是ip协议第4版本,也表示这个版本的ip一共4个字节,同样地,ipv6是ip协议第6版本,也表示这个版本的ip一共6个字节。 关于网络层使用路由器实现互联:在计算机网络的分层结构中,不同层有不同的中继设备: 计算机网络层 中继设备/中继系统 物理层 中继器、集线器Hub 数据链路层 网桥或交换机(交换机是多端口网桥,两者本质上是一个东西) 网络层 路...



技术大佬:我去,你写的 switch 语句也太老土了吧

昨天早上通过远程的方式 review 了两名新来同事的代码,大部分代码都写得很漂亮,严谨的同时注释也很到位,这令我非常满意。但当我看到他们当中有一个人写的 switch 语句时,还是忍不住破口大骂:“我擦,小王,你丫写的 switch 语句也太老土了吧!” 来看看小王写的代码吧,看完不要骂我装逼啊。 private static String createPlayer(PlayerTypes p...


华为面试整体流程大致分为笔试,性格测试,面试,综合面试,回学校等结果。笔试来说,华为的难度较中等,选择题难度和网易腾讯差不多。最后的代码题,相比下来就简单很多,一共3道题目,前2题很容易就AC,题目已经记不太清楚,不过难度确实不大。最后一题最后提交的代码过了75%的样例,一直没有发现剩下的25%可能存在什么坑。 笔试部分太久远,我就不怎么回忆了。直接将面试。 面试 如果说腾讯的面试是挥金如土...

和黑客斗争的 6 天!

互联网公司工作,很难避免不和黑客们打交道,我呆过的两家互联网公司,几乎每月每天每分钟都有黑客在公司网站上扫描。有的是寻找 Sql 注入的缺口,有的是寻找线上服务器可能存在的漏洞,大部分都...



总结了 150 余个神奇网站,你不来瞅瞅吗?



提到“程序员”,多数人脑海里首先想到的大约是:为人木讷、薪水超高、工作枯燥…… 然而,当离开工作岗位,撕去层层标签,脱下“程序员”这身外套,有的人生动又有趣,马上展现出了完全不同的A/B面人生! 不论是简单的爱好,还是正经的副业,他们都干得同样出色。偶尔,还能和程序员的特质结合,产生奇妙的“化学反应”。 @Charlotte:平日素颜示人,周末美妆博主 大家都以为程序媛也个个不修边幅,但我们也许...




女朋友说:“看你最近挺辛苦的,我送你一个礼物吧。你看看想要什么,我来准备。” 我想了半天,从书到鞋子到电子产品最后到生活用品,感觉自己什么都不缺,然后和她说:“你省省钱吧,我什么都不需要。” 她坚持要送:“不行,你一定要说一个礼物,我想送你东西了。” 于是,我认真了起来,拿起手机,上淘宝逛了几分钟,但还是没能想出来缺点什么,最后实在没办法了:“这样吧,如果你实在想送东西,那你就写一个代理服务器吧”...






即将毕业的应届毕业生一枚,现在只拿到了两家offer,但最近听到一些消息,其中一个offer,我这个组据说客户很少,很有可能整组被裁掉。 想问大家: 如果我刚入职这个组就被裁了怎么办呢? 大家都是什么时候知道自己要被裁了的? 面试软技能指导: BQ/Project/Resume 试听内容: 除了刷题,还有哪些技能是拿到offer不可或缺的要素 如何提升面试软实力:简历, 行为面试,沟通能...

离职半年了,老东家又发 offer,回不回?

有小伙伴问松哥这个问题,他在上海某公司,在离职了几个月后,前公司的领导联系到他,希望他能够返聘回去,他很纠结要不要回去? 俗话说好马不吃回头草,但是这个小伙伴既然感到纠结了,我觉得至少说明了两个问题:1.曾经的公司还不错;2.现在的日子也不是很如意。否则应该就不会纠结了。 老实说,松哥之前也有过类似的经历,今天就来和小伙伴们聊聊回头草到底吃不吃。 首先一个基本观点,就是离职了也没必要和老东家弄的苦...


阿里巴巴全球数学竞赛( Alibaba Global Mathematics Competition)由马云发起,由中国科学技术协会、阿里巴巴基金会、阿里巴巴达摩院共同举办。大赛不设报名门槛,全世界爱好数学的人都可参与,不论是否出身数学专业、是否投身数学研究。 2020年阿里巴巴达摩院邀请北京大学、剑桥大学、浙江大学等高校的顶尖数学教师组建了出题组。中科院院士、美国艺术与科学院院士、北京国际数学...








当HR压你价,说你只值7K时,你可以流畅地回答,记住,是流畅,不能犹豫。 礼貌地说:“7K是吗?了解了。嗯~其实我对贵司的面试官印象很好。只不过,现在我的手头上已经有一份11K的offer。来面试,主要也是自己对贵司挺有兴趣的,所以过来看看……”(未完) 这段话主要是陪HR互诈的同时,从公司兴趣,公司职员印象上,都给予对方正面的肯定,既能提升HR的好感度,又能让谈判气氛融洽,为后面的发挥留足空间。...


HashMap底层实现原理,红黑树,B+树,B树的结构原理 Spring的AOP和IOC是什么?它们常见的使用场景有哪些?Spring事务,事务的属性,传播行为,数据库隔离级别 Spring和SpringMVC,MyBatis以及SpringBoot的注解分别有哪些?SpringMVC的工作原理,SpringBoot框架的优点,MyBatis框架的优点 SpringCould组件有哪些,他们...