Adding server for code generation
This commit is contained in:
parent
62c6805a74
commit
40291a96dd
4 changed files with 234 additions and 0 deletions
73
server/static/home.html
Normal file
73
server/static/home.html
Normal file
|
@ -0,0 +1,73 @@
|
|||
<html>
|
||||
<title>jsonenums</title>
|
||||
<style>
|
||||
textarea,
|
||||
input {
|
||||
display: block;
|
||||
width: 80%;
|
||||
margin: auto;
|
||||
}
|
||||
textarea {
|
||||
height: 200px;
|
||||
overflow-y: scroll;
|
||||
}
|
||||
</style>
|
||||
|
||||
<script src="https://code.jquery.com/jquery-2.1.3.min.js"></script>
|
||||
<script>
|
||||
function generate() {
|
||||
$.get("/generate", {
|
||||
"code": $("#code").val(),
|
||||
"type": $("#type").val(),
|
||||
"template": $("#template").val(),
|
||||
}).done(function(res) {
|
||||
$("#result").val(res);
|
||||
$("#result").css('background','#fff');
|
||||
}).fail(function(res) {
|
||||
$("#result").val(res.responseText);
|
||||
$("#result").css('background','#fee');
|
||||
})
|
||||
}
|
||||
</script>
|
||||
|
||||
<body>
|
||||
|
||||
<form action="/generate" method="GET">
|
||||
<input type="text" id="type" value="WeekDay">
|
||||
<textarea id="code">
|
||||
package test
|
||||
|
||||
type WeekDay int
|
||||
|
||||
const (
|
||||
Monday WeekDay = iota
|
||||
Tuesday
|
||||
Wednesday
|
||||
Thursday
|
||||
Friday
|
||||
Saturday
|
||||
Sunday
|
||||
)
|
||||
</textarea>
|
||||
<textarea id="template">
|
||||
package {{.PackageName}}
|
||||
|
||||
func (r {{.TypeName}}) String() string {
|
||||
s, ok := map[{{.TypeName}}]string {
|
||||
{{range .Values}}{{.}}:"{{.}}",{{end}}
|
||||
}
|
||||
if !ok {
|
||||
return "unknown {{.TypeName}}"
|
||||
}
|
||||
return s
|
||||
}
|
||||
</textarea>
|
||||
</form>
|
||||
|
||||
<input type="button" onclick="generate()" value="generate code">
|
||||
|
||||
<textarea id="result">
|
||||
</textarea>
|
||||
</body>
|
||||
|
||||
</html>
|
Loading…
Add table
Add a link
Reference in a new issue