Coder Social home page Coder Social logo

bookstore's Introduction

Generating Golang Server Stubs / API code

The following instructions are a "somewhat more detailed" adaptation of instructions described in

  • Download swagger codegen (to ~/apps in this example)
  • Execute the following to generate the golang server stub in the app directory
java -jar  ~/apps/swagger-codegen-3.0.34/modules/swagger-codegen-cli/target/swagger-codegen-cli.jar generate \
  -i bookstore.yaml \
  -l go-server \
  -o app
  • cd app

Execute the application

  • Option 1: Execute the application directly
    • In main.go , fix the path to the sw import eg sw "github.com/balamuru/bookstore/app/go"
    • go mod init
    • go mod tidy
    • go run main.go
  • Option 2: Build the application within Docker
    • Build image 'docker build . -t bookstore' . In case this image is built on a machine behind a proxy, be sure to pass the proxies as command args docker build . -t bookstore --build-arg http_proxy --build-arg https_proxy
    • Start container docker run -it -p8080:8080 bookstore

Access the stub API

  • Use the appropriate client eg curl -v http://localhost:8080/vgb/bookstore/1.0/shelves
$ curl -v http://localhost:8080/vgb/bookstore/1.0/shelves
* About to connect() to localhost port 8080 (#0)
*   Trying ::1...
* Connected to localhost (::1) port 8080 (#0)
> GET /vgb/bookstore/1.0/shelves HTTP/1.1
> User-Agent: curl/7.29.0
> Host: localhost:8080
> Accept: */*
> 
< HTTP/1.1 200 OK
< Content-Type: application/json; charset=UTF-8
< Date: Mon, 25 Apr 2022 19:53:43 GMT
< Content-Length: 0
< 
* Connection #0 to host localhost left intact

bookstore's People

Contributors

balamuru avatar

Stargazers

 avatar

Watchers

 avatar

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.