Skip to content

Commit

Permalink
add valitation tag
Browse files Browse the repository at this point in the history
  • Loading branch information
John-Lin committed Jul 16, 2018
1 parent ddf35c0 commit 1537f90
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/entity/volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ const (
So the Volume will create a PVC type and connect to a known StorageClass
*/
type Volume struct {
ID bson.ObjectId `bson:"_id,omitempty" json:"id"`
Name string `bson:"name" json:"name"`
StorageName string `bson:"storageName" json:"storageName"`
AccessMode corev1.PersistentVolumeAccessMode `bson:"accessMode" json:"accessMode"`
Capacity string `bson:"capacity" json:"capacity"`
CreatedAt *time.Time `bson:"createdAt,omitempty" json:"createdAt,omitempty"`
ID bson.ObjectId `bson:"_id,omitempty" json:"id" validate:"-"`
Name string `bson:"name" json:"name" validate:"required"`
StorageName string `bson:"storageName" json:"storageName" validate:"required"`
AccessMode corev1.PersistentVolumeAccessMode `bson:"accessMode" json:"accessMode" validate:"required"`
Capacity string `bson:"capacity" json:"capacity" validate:"required"`
CreatedAt *time.Time `bson:"createdAt,omitempty" json:"createdAt,omitempty" validate:"-"`
}

//GetCollection - get model mongo collection name.
Expand Down
5 changes: 5 additions & 0 deletions src/server/handler_volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ func createVolume(ctx *web.Context) {
return
}

if err := sp.Validator.Struct(v); err != nil {
response.BadRequest(req.Request, resp.ResponseWriter, err)
return
}

session := sp.Mongo.NewSession()
session.C(entity.VolumeCollectionName).EnsureIndex(mgo.Index{
Key: []string{"name"},
Expand Down

0 comments on commit 1537f90

Please sign in to comment.