func (u *UniterAPIV3) charmModifiedVersion(tagStr string, canAccess func(names.Tag) bool) (int, error) { tag, err := names.ParseTag(tagStr) if err != nil { return -1, common.ErrPerm } if !canAccess(tag) { return -1, common.ErrPerm } unitOrService, err := u.st.FindEntity(tag) if err != nil { return -1, err } var service *state.Application switch entity := unitOrService.(type) { case *state.Application: service = entity case *state.Unit: service, err = entity.Application() if err != nil { return -1, err } default: return -1, errors.BadRequestf("type %T does not have a CharmModifiedVersion", entity) } return service.CharmModifiedVersion(), nil }