Coder Social home page Coder Social logo

corylanou / tns-restful-json-api Goto Github PK

View Code? Open in Web Editor NEW
858.0 40.0 277.0 14 KB

This is the code repository that goes along with the "TheNewStack" article for RESTful JSON API post

License: MIT License

Go 100.00%
golang tutorial restful json-api article go

tns-restful-json-api's People

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

tns-restful-json-api's Issues

Great article!

Just wanted to say thanks for the article! I'm getting started with Go and it was great, learned a ton! Thanks! 😄

About post complex data

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

Add a license file

Can we have a license file so we can reuse this code with the author's permission?

undefined: NewRouter

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.

race condition

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.

Issue with variables.

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                                                                                                                                                                          
  }  

./main.go:10: undefined: NewRouter

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

Server is not responding when I try to retrieve document info from curl

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

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.