corylanou / tns-restful-json-api Goto Github PK
View Code? Open in Web Editor NEWThis is the code repository that goes along with the "TheNewStack" article for RESTful JSON API post
License: MIT License
This is the code repository that goes along with the "TheNewStack" article for RESTful JSON API post
License: MIT License
Just wanted to say thanks for the article! I'm getting started with Go and it was great, learned a ton! Thanks! 😄
json.Unmarshal(body, &todo)
in the actual project, post data is complex,how can i define struct type? how can i parse these post data,thank you
Can we have a license file so we can reuse this code with the author's permission?
hi,i'm glad to see your ariticle,i'm a new student,in the actual project,has user api,goods api...,we can not write all codes in hanlers.go,how can i organize directory?how can i let code run?
Hello, in first thanks for your tutorial :)
I have a problem when try execute go run main.go
I get message # command-line-arguments ./main.go:10: undefined: NewRouter
.
Hello,
I guess there will be race condition in the example, since the two global variables can be accessed simultaneously by different HTTP handlers, which can be executed in different goroutines.
In: https://github.com/corylanou/tns-restful-json-api/blob/master/v9/logger.go#L10
I'm getting the following error:
○ → go run *
# command-line-arguments
./logger.go:23: not enough arguments in call to http.HandleFunc
./logger.go:23: http.HandleFunc(func literal) used as value
i added route under routes like this
Route{
"Js",
"GET",
"/js",
Js,
},
and under my main package i have a function like this
func Js(w http.ResponseWriter, r *http.Request) {
fmt.Println("boom!!!")
http.StripPrefix("/js/", http.FileServer(http.Dir("public/js/")))
}
and when i try to access my bundel.js like this it shows 404
Trying to figure this out.
My example:
localhost:8080/ticket/ticketid/info?secret=key
For some reason, mux isn't picking up the 'secret' variable. Any idea?
func TicketInfo(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json; charset=UTF-8")
vars := mux.Vars(r)
fmt.Println(vars["secret"])
// check admin secretkey
if CheckSecret(vars["secret"]) == false {
if err := json.NewEncoder(w).Encode(&ErrResponse{Status: "error", ErrorDescription: "invalid secret key"}); err != nil {
panic(err)
}
w.WriteHeader(http.StatusNotFound)
return
}
Hi,
I am having issues when runngin go get on v9 of the project. I get the following error
./main.go:10: undefined: NewRouter
Can anyone explain what is wrong. I have checked my goroot, gobin and gopath variables and they all seem fine.
Thanks
Jonathan
Hi,
First the server is answering correctly when I do that:
>curl -i "http://localhost:8080"
HTTP/1.1 200 OK
Date: Wed, 23 Sep 2015 10:37:26 GMT
Content-Length: 9
Content-Type: text/plain; charset=utf-8
Welcome!
But when I try to get only the document info, I have that:
>curl -I "http://localhost:8080"
HTTP/1.1 404 Not Found
Content-Type: text/plain; charset=utf-8
X-Content-Type-Options: nosniff
Date: Wed, 23 Sep 2015 10:36:50 GMT
Content-Length: 19
-I, --head Show document info only
It seems that the request is not even rooted. My aim is to enable CORS Support on the server side to use swagger.
https://github.com/swagger-api/swagger-ui/blob/master/README.md#cors-support
I am expected this kind of response
>curl -I "http://localhost:8080"
HTTP/1.1 200 OK
Date: Sat, 31 Jan 2015 23:05:44 GMT
Access-Control-Allow-Origin: *
Access-Control-Allow-Methods: GET, POST, DELETE, PUT, PATCH, OPTIONS
Access-Control-Allow-Headers: Content-Type, api_key, Authorization
Content-Type: application/json
Content-Length: 0
I do not know what to do in the code to achieve this. Do you have any idea ?
Thanks
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.