Skip to content

Commit

Permalink
Fix errors from previous commit
Browse files Browse the repository at this point in the history
-

- remove idea folder

- refactored code
- spearated out models from the main code
- changed the template
- added some more duplication avoiding logic
- added persistence
  • Loading branch information
SDkie authored and Akshay Deo committed Oct 26, 2015
1 parent 0757426 commit a1ca7b6
Show file tree
Hide file tree
Showing 18 changed files with 442 additions and 269 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,6 @@
filters/*.html
examples/core/core
examples/core/server
*/*.iml
.idea/*
examples/*.html
Binary file modified 1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified 2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func handler(w http.ResponseWriter, r *http.Request) {
}

func main() {
yaag.Init(&yaag.Config{On: true, DocTitle: "Core", DocPath: "apidoc.html"})
yaag.Init(&yaag.Config{On: true, DocTitle: "Core", DocPath: "apidoc.html", BaseUrls : map[string]string{"Production":"","Staging":""} })
http.HandleFunc("/", middleware.HandleFunc(handler))
http.ListenAndServe(":8080", nil)
}
Expand Down
156 changes: 156 additions & 0 deletions examples/core/apidoc.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
<!DOCTYPE html>
<html>
<head lang="en">
<title> API Documentation </title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css">
<script src="http://google-code-prettify.googlecode.com/svn/loader/run_prettify.js"></script>
<link href='http://fonts.googleapis.com/css?family=Roboto' rel='stylesheet' type='text/css'>
<link rel="stylesheet" href="http://google-code-prettify.googlecode.com/svn/trunk/src/prettify.css">

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap-theme.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>

<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/js/bootstrap.min.js"></script>
<style type="text/css">
body {
font-family: 'Roboto', sans-serif;
}
.hidden {
display:none;
}
</style>
<style type="text/css">
pre.prettyprint {
border: 1px solid #ccc;
margin-bottom: 0;
padding: 9.5px;
}
</style>
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/8.4/highlight.min.js"></script>
<script>
hljs.initHighlightingOnLoad();
function toggler(divId) {
$("#" + divId).toggle();
}
</script>
</head>
<body>
<nav class="navbar navbar-default navbar-fixed-top">
<div class="container-fluid">

<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse"
data-target="#bs-example-navbar-collapse-1">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">Core</a>
<p class="navbar-text">Developed by Gophers at <a href="http://betacraft.co">Betacraft</a></p>
</div>


</div>

</nav>
<div class="container-fluid" style="margin-top: 70px;margin-bottom: 20px;">
<div class="container-fluid">
<div class="col-md-4">
<div class="panel panel-default">
<div class="panel-heading">Base Urls</div>
<div class="panel-body">

<p>Production : <strong>http://testing.com</strong></p>

</div>
</div>
<ul class="nav nav-pills nav-stacked" role="tablist">

<li role="presentation"><a href="#0top" role="tab" data-toggle="tab">GET : /</a></li>

<li role="presentation"><a href="#1top" role="tab" data-toggle="tab">POST : /say_it</a></li>

<ul>
</div>
<div class="col-md-8 tab-content">

<div id="0top" role="tabpanel" class="tab-pane col-md-10">


<p> <H4> Request Headers </H4> </p>
<table class="table table-bordered table-striped">
<tr>
<th>Key</th>
<th>Value</th>
</tr>

<tr>
<td>Content-Type</td>
<td> application/json</td>
</tr>

</table>




<p><h4> Response Code</h4></p>
<pre class="prettyprint lang-json">200</pre>


<p> <H4> Response Body </H4> </p>
<pre class="prettyprint lang-json">Hi there, I love !</pre>

<hr>

</div>

<div id="1top" role="tabpanel" class="tab-pane col-md-10">


<p> <H4> Request Headers </H4> </p>
<table class="table table-bordered table-striped">
<tr>
<th>Key</th>
<th>Value</th>
</tr>

<tr>
<td>Content-Type</td>
<td> application/json</td>
</tr>

</table>




<p><h4> Response Code</h4></p>
<pre class="prettyprint lang-json">200</pre>

<p><h4> Response Headers</h4></p>
<table class="table table-bordered table-striped">
<tr>
<th>Key</th>
<th>Value</th>
</tr>

<tr>
<td>Test</td>
<td> tesasasdasd</td>
</tr>

</table>


<hr>

</div>

</div>
</div>
</div>
<hr>
</body>
</html>
Expand Down
1 change: 1 addition & 0 deletions examples/core/apidoc.html.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"ApiSpecs":[{"HttpVerb":"GET","Path":"/","Calls":[{"Id":0,"CurrentPath":"/","MethodType":"GET","PostForm":null,"RequestHeader":{"Content-Type":" application/json\r"},"CommonRequestHeaders":null,"ResponseHeader":{},"RequestUrlParams":{},"RequestBody":"","ResponseBody":"Hi there, I love !","ResponseCode":200}]},{"HttpVerb":"POST","Path":"/say_it","Calls":[{"Id":1,"CurrentPath":"/say_it","MethodType":"POST","PostForm":null,"RequestHeader":{"Content-Type":" application/json\r"},"CommonRequestHeaders":null,"ResponseHeader":{"Test":"tesasasdasd"},"RequestUrlParams":{},"RequestBody":"","ResponseBody":"","ResponseCode":200}]}]}
2 changes: 1 addition & 1 deletion examples/core/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func postHandler(w http.ResponseWriter, r *http.Request) {
}

func main() {
yaag.Init(&yaag.Config{On: true, DocTitle: "Core", DocPath: "apidoc.html"})
yaag.Init(&yaag.Config{On: true, DocTitle: "Core", DocPath: "apidoc.html", BaseUrls: map[string]string{"Production": "http://testing.com"}})
http.HandleFunc("/", middleware.HandleFunc(handler))
http.HandleFunc("/say_it", middleware.HandleFunc(postHandler))
http.ListenAndServe(":8080", nil)
Expand Down
2 changes: 1 addition & 1 deletion examples/gorilla_mux/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func postHandler(w http.ResponseWriter, r *http.Request) {
}

func main() {
yaag.Init(&yaag.Config{On: true, DocTitle: "Gorilla Mux", DocPath: "apidoc.html"})
yaag.Init(&yaag.Config{On: true, DocTitle: "Gorilla Mux", DocPath: "apidoc.html", BaseUrls: map[string]string{"Production": "", "Staging": ""}})
r := mux.NewRouter()
r.HandleFunc("/", middleware.HandleFunc(handler))
r.HandleFunc("/testing", middleware.HandleFunc(postHandler)).Methods("POST")
Expand Down
2 changes: 1 addition & 1 deletion examples/martini/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
)

func main() {
yaag.Init(&yaag.Config{On: true, DocTitle: "Gorilla Mux", DocPath: "apidoc.html"})
yaag.Init(&yaag.Config{On: true, DocTitle: "Gorilla Mux", DocPath: "apidoc.html", BaseUrls: map[string]string{"Production": "", "Staging": ""}})
m := martini.Classic()
m.Use(martiniyaag.Document)
m.Get("/", func() string {
Expand Down
16 changes: 5 additions & 11 deletions middleware/yaagmiddleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"strings"

"github.com/betacraft/yaag/yaag"
"github.com/betacraft/yaag/yaag/models"
)

var reqWriteExcludeHeaderDump = map[string]bool{
Expand Down Expand Up @@ -45,7 +46,7 @@ func (y *YaagHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
return
}
writer := httptest.NewRecorder()
apiCall := yaag.APICall{}
apiCall := models.ApiCall{}
Before(&apiCall, r)
y.nextHandler.ServeHTTP(writer, r)
After(&apiCall, writer, w, r)
Expand All @@ -57,15 +58,15 @@ func HandleFunc(next func(http.ResponseWriter, *http.Request)) func(http.Respons
next(w, r)
return
}
apiCall := yaag.APICall{}
apiCall := models.ApiCall{}
writer := httptest.NewRecorder()
Before(&apiCall, r)
next(writer, r)
After(&apiCall, writer, w, r)
}
}

func Before(apiCall *yaag.APICall, req *http.Request) {
func Before(apiCall *models.ApiCall, req *http.Request) {
apiCall.RequestHeader = ReadHeaders(req)
apiCall.RequestUrlParams = ReadQueryParams(req)
val, ok := apiCall.RequestHeader["Content-Type"]
Expand Down Expand Up @@ -171,7 +172,7 @@ func ReadBody(req *http.Request) *string {
return &body
}

func After(apiCall *yaag.APICall, writer *httptest.ResponseRecorder, w http.ResponseWriter, r *http.Request) {
func After(apiCall *models.ApiCall, writer *httptest.ResponseRecorder, w http.ResponseWriter, r *http.Request) {
if strings.Contains(r.RequestURI, ".ico") {
fmt.Fprintf(w, writer.Body.String())
return
Expand All @@ -182,13 +183,6 @@ func After(apiCall *yaag.APICall, writer *httptest.ResponseRecorder, w http.Resp
apiCall.ResponseBody = writer.Body.String()
apiCall.ResponseCode = writer.Code
apiCall.ResponseHeader = ReadHeadersFromResponse(writer)
var baseUrl string
if r.TLS != nil {
baseUrl = fmt.Sprintf("https://%s", r.Host)
} else {
baseUrl = fmt.Sprintf("http://%s", r.Host)
}
yaag.ApiCallValueInstance.BaseLink = baseUrl
go yaag.GenerateHtml(apiCall)
}
for key, value := range apiCall.ResponseHeader {
Expand Down
Loading

0 comments on commit a1ca7b6

Please sign in to comment.