github.com/kotovmak/go-admin@v1.1.1/template/types/display/downloadable.go (about)

     1  package display
     2  
     3  import (
     4  	"html/template"
     5  
     6  	"github.com/kotovmak/go-admin/template/types"
     7  )
     8  
     9  type Downloadable struct {
    10  	types.BaseDisplayFnGenerator
    11  }
    12  
    13  func init() {
    14  	types.RegisterDisplayFnGenerator("downloadable", new(Downloadable))
    15  }
    16  
    17  func (d *Downloadable) Get(args ...interface{}) types.FieldFilterFn {
    18  	return func(value types.FieldModel) interface{} {
    19  		param := args[0].([]string)
    20  
    21  		u := value.Value
    22  
    23  		if len(param) > 0 {
    24  			u = param[0] + u
    25  		}
    26  
    27  		return template.HTML(`
    28  <a href="` + u + `" download="` + value.Value + `" target="_blank" class="text-muted">
    29  	<i class="fa fa-download"></i> ` + value.Value + `
    30  </a>
    31  `)
    32  	}
    33  }