-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Test] coverage code by tests
- Loading branch information
Showing
12 changed files
with
391 additions
and
107 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,35 @@ | ||
package diago | ||
|
||
import "github.com/gin-gonic/gin" | ||
|
||
type Extension interface { | ||
GetPanelHtml(c *gin.Context) string | ||
GetHtml(c *gin.Context) string | ||
GetJSHtml(c *gin.Context) string | ||
BeforeNext(c *gin.Context) | ||
AfterNext(c *gin.Context) | ||
} | ||
|
||
type Diago struct { | ||
Extensions []DiagoExtension | ||
Extensions []Extension | ||
|
||
TemplateProvider TemplateProvider | ||
PanelGenerator PanelGenerator | ||
} | ||
|
||
func NewDiago() *Diago { | ||
return &Diago{} | ||
|
||
return &Diago{ | ||
TemplateProvider: NewDefaultTemplateProvider(), | ||
PanelGenerator: NewDefaultPanelGenerator(), | ||
} | ||
} | ||
|
||
func (d *Diago) GetExtensions() []DiagoExtension { | ||
func (d *Diago) GetExtensions() []Extension { | ||
return d.Extensions | ||
} | ||
|
||
func (d *Diago) AddExtension(extension DiagoExtension) *Diago { | ||
func (d *Diago) AddExtension(extension Extension) *Diago { | ||
d.Extensions = append(d.Extensions, extension) | ||
return d | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package diago | ||
|
||
import ( | ||
"errors" | ||
"html/template" | ||
"strings" | ||
) | ||
|
||
type TemplateProvider interface { | ||
GetTemplate() string | ||
} | ||
|
||
type PanelGenerator interface { | ||
GenerateHTML(name string, templateProvider TemplateProvider, data interface{}) (string, error) | ||
} | ||
|
||
type DefaultPanelGenerator struct{} | ||
|
||
type DefaultTemplateProvider struct{} | ||
|
||
func (p DefaultTemplateProvider) GetTemplate() string { | ||
return GetDiagoPanelTemplate() | ||
} | ||
|
||
func (d *DefaultPanelGenerator) GenerateHTML(name string, templateProvider TemplateProvider, data interface{}) (string, error) { | ||
templateContent := templateProvider.GetTemplate() | ||
tp := template.New(name) | ||
if tp == nil { | ||
return "", errors.New("Bad template name") | ||
} | ||
tpl, err := tp.Parse(templateContent) | ||
if err != nil { | ||
return "", err | ||
} | ||
|
||
var builder strings.Builder | ||
|
||
err = tpl.Execute(&builder, data) | ||
if err != nil { | ||
return "", err | ||
} | ||
|
||
return builder.String(), nil | ||
} | ||
|
||
func NewDefaultPanelGenerator() *DefaultPanelGenerator { | ||
return &DefaultPanelGenerator{} | ||
} | ||
|
||
func NewDefaultTemplateProvider() *DefaultTemplateProvider { | ||
return &DefaultTemplateProvider{} | ||
} |
Oops, something went wrong.