@@ -55,8 +55,10 @@ func init() {
55
55
versionRegex = regexp .MustCompile ("^" + semVerRegex + "$" )
56
56
}
57
57
58
- const num string = "0123456789"
59
- const allowed string = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-" + num
58
+ const (
59
+ num string = "0123456789"
60
+ allowed string = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-" + num
61
+ )
60
62
61
63
// StrictNewVersion parses a given version and returns an instance of Version or
62
64
// an error if unable to parse the version. Only parses valid semantic versions.
@@ -284,7 +286,6 @@ func (v Version) Metadata() string {
284
286
285
287
// originalVPrefix returns the original 'v' prefix if any.
286
288
func (v Version ) originalVPrefix () string {
287
-
288
289
// Note, only lowercase v is supported as a prefix by the parser.
289
290
if v .original != "" && v .original [:1 ] == "v" {
290
291
return v .original [:1 ]
@@ -453,6 +454,23 @@ func (v Version) MarshalJSON() ([]byte, error) {
453
454
return json .Marshal (v .String ())
454
455
}
455
456
457
+ // UnmarshalText implements the encoding.TextUnmarshaler interface.
458
+ func (v * Version ) UnmarshalText (text []byte ) error {
459
+ temp , err := NewVersion (string (text ))
460
+ if err != nil {
461
+ return err
462
+ }
463
+
464
+ * v = * temp
465
+
466
+ return nil
467
+ }
468
+
469
+ // MarshalText implements the encoding.TextMarshaler interface.
470
+ func (v Version ) MarshalText () ([]byte , error ) {
471
+ return []byte (v .String ()), nil
472
+ }
473
+
456
474
// Scan implements the SQL.Scanner interface.
457
475
func (v * Version ) Scan (value interface {}) error {
458
476
var s string
@@ -487,7 +505,6 @@ func compareSegment(v, o uint64) int {
487
505
}
488
506
489
507
func comparePrerelease (v , o string ) int {
490
-
491
508
// split the prelease versions by their part. The separator, per the spec,
492
509
// is a .
493
510
sparts := strings .Split (v , "." )
@@ -579,7 +596,6 @@ func comparePrePart(s, o string) int {
579
596
return 1
580
597
}
581
598
return - 1
582
-
583
599
}
584
600
585
601
// Like strings.ContainsAny but does an only instead of any.
0 commit comments