diff --git a/cmd/definitions/bindata.go b/cmd/definitions/bindata.go index e73021f8b..6e9c0201b 100644 --- a/cmd/definitions/bindata.go +++ b/cmd/definitions/bindata.go @@ -5,7 +5,7 @@ // cmd/definitions/tmpl/object.tmpl (1.907kB) // cmd/definitions/tmpl/operation.tmpl (1.698kB) // cmd/definitions/tmpl/pair.tmpl (502B) -// cmd/definitions/tmpl/service.tmpl (11.358kB) +// cmd/definitions/tmpl/service.tmpl (11.565kB) // +build tools @@ -176,7 +176,7 @@ func cmdDefinitionsTmplPairTmpl() (*asset, error) { return a, nil } -var _cmdDefinitionsTmplServiceTmpl = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xec\x1a\x5d\x6f\xdc\xb8\xf1\x7d\x7f\xc5\x9c\x60\x04\xbb\xc1\x46\x6a\x81\x3e\x6d\xe1\x87\xab\x93\x4b\x8d\x4b\x13\x23\xce\xf5\x1e\xee\x0e\x06\x2d\x8d\x76\x59\x4b\xa4\x8e\xe4\xae\x63\x6c\xf4\xdf\x8b\x21\xa9\x6f\x69\x3f\xd2\x14\x97\x16\xf1\x8b\x57\xe4\xcc\x70\xbe\x3f\x28\x45\x11\x5c\xc9\x04\x61\x8d\x02\x15\x33\x98\xc0\xfd\x13\xac\x65\xfd\x0c\x3b\xce\x20\xce\x93\x28\xc1\x94\x0b\x6e\xb8\x14\xfa\xaf\xf0\xf2\x1d\xbc\x7d\xf7\x01\x5e\xbd\xbc\xfe\x10\xce\x0a\x16\x3f\xb0\x35\xc2\x7e\x0f\xe1\x5b\x96\x23\x94\xe5\x6c\xc6\xf3\x42\x2a\x03\xf3\x19\x00\x40\x10\x4b\x61\xf0\xa3\x09\xdc\x13\x97\xc1\xcc\xfd\x5a\x73\xb3\xd9\xde\x87\xb1\xcc\xa3\x7b\x7c\x92\x22\xd1\x46\x2a\xb6\xc6\x68\x2d\x5f\x54\x3f\x77\x7f\x89\x8a\x87\x75\x84\x22\x29\x24\x17\x15\x8d\x33\x30\x63\x85\x09\x0a\xc3\x59\x76\x3e\xee\xc6\x98\x22\xce\x38\x9e\x7b\xae\x46\xb5\xe3\x31\x6a\x87\x15\x9e\x8c\x67\x9e\x0a\x42\x5a\xcc\x66\x3b\xa6\xe0\x0e\x1a\xde\xc3\x1b\x25\x77\x3c\x41\xe5\x77\x2a\x7d\x84\xff\x64\xd9\x16\xfd\xe2\xad\xa3\x54\xc1\x54\x5c\x84\xb7\xee\xc7\x2b\xa5\x64\xb5\xd7\x48\x16\xbe\x2b\xac\x59\x67\xb3\x28\x82\x0f\x4f\x05\x02\xd7\x60\x36\x08\xc4\x0c\xa4\x52\x75\x2c\x1b\x4b\xa1\x8d\x03\xbb\x84\xa0\xb5\x13\x58\xfc\x77\xf7\xff\xc2\xd8\xfc\x03\x0d\x4b\x98\x61\x40\xa2\xa1\xae\x18\x81\xbc\x5a\x27\xaa\xd2\x82\x86\x33\x7b\xcc\x00\x4f\x6d\x63\x03\xfb\xd9\x7e\xff\x02\x14\x13\x6b\x84\x8b\xbb\x25\x5c\xec\x60\x75\x09\xe1\xb5\x48\xa5\x26\x66\x48\xb9\x04\xc1\x53\x10\xd2\xc0\xc5\x2e\x7c\x9d\xc9\x7b\x96\xb5\xf7\x2e\x0a\x41\x0c\xae\x2e\x69\xdb\xf2\xfa\x09\x8c\xbc\x61\x3a\xee\xc2\xf1\x94\x00\x5e\x72\x5d\x64\xec\xa9\x92\x16\xfc\x5f\x8b\xd0\xe5\x04\x18\x81\xa0\x48\x9a\x47\x0b\x87\x3a\x56\xdc\xea\xb7\xbd\xe1\x28\x95\xa5\x87\xb2\xda\x1c\x92\x69\xfd\x2c\xad\x72\x5f\xa3\xe9\xe9\xe9\x91\x67\x19\xac\xd1\xf4\xf5\x97\x2a\x99\xfb\xb5\x70\x16\x45\x84\xfc\x02\x3e\x6c\xb8\x86\x74\x2b\x62\xcb\x8e\xde\xc8\x6d\x96\x58\xbd\xdd\x23\xc4\x2c\xcb\x5c\xf0\x57\xb6\xe2\x79\x91\x61\x8e\xc2\xa0\x0a\x2b\x7c\x04\x85\x66\xab\x04\x17\xeb\xfe\x89\x5c\x83\x42\x96\x80\x14\xd9\x13\x30\x91\xf4\xe8\xe7\x32\xe1\x29\xc7\x24\x9c\x11\x03\x43\x49\xe6\x12\x9e\xbb\x95\x45\x9f\xf2\xde\xea\x45\xe6\x4b\x90\x0f\x64\x46\x19\xbe\x46\xe3\x3d\xba\x46\x5f\x58\x20\x9e\x12\xcc\xbe\x36\x9b\xe3\x16\x64\x1e\xce\xbb\x44\x1d\xb8\xd3\xb8\x07\xea\x02\xec\x2b\x9d\xeb\x71\x9d\xeb\xa1\xce\xb9\x30\xf2\x34\x9d\x5b\x1d\x35\x4a\x97\x22\xc6\x25\x14\x19\x32\x8d\x90\xb3\x07\x04\xbd\x55\x08\x2c\xcb\xc0\x12\xde\x30\x0d\xf7\x88\x02\x1e\x15\x37\x06\x05\xdc\x63\x2a\x15\x12\x0f\x5e\x9d\x03\x26\x1b\x75\x2e\xa1\xf6\x84\x5a\xf8\x4a\xa5\xe1\xed\x50\x91\x32\x5f\x90\xe4\xa3\x71\x77\xc3\xb8\xd2\x95\x67\x8e\xc5\xdc\x29\xf1\xd6\xc4\xda\x95\x14\x69\xc6\x63\x43\xab\x51\x04\x2f\xb1\x50\x18\x53\x0d\x5a\xc1\x4f\x1a\xa1\xa0\xd3\xc2\x9f\xb9\xd9\x74\x42\x86\x0b\x6d\x90\x25\x56\xc5\xad\x08\x89\x22\x18\x80\x5a\x4b\xb1\xa2\xc8\x9e\x7c\xa0\xf9\x78\x85\x1d\xe5\x4c\x20\x73\xb9\xd4\xe7\x89\x8d\x44\xac\x55\x6f\x9f\xf0\x7c\xd7\x0d\xdc\x05\x90\x66\x86\x7e\x47\xab\xcd\xe2\x8f\xf8\xb4\xb2\x19\xb3\x61\x24\x58\xd6\xbb\x36\x8d\xaf\x60\xb7\xf4\x9e\xd9\x09\xff\xd6\xcf\x71\xcb\x10\x3d\x5d\xb0\x18\x3b\x69\xd1\x60\x5e\x64\x54\xc4\x03\x4e\x61\x9c\xd2\x7e\x60\x3d\xec\x36\xa3\x10\xaf\x18\xb9\xd8\x85\xd7\x35\xc0\x38\x81\x14\x99\xd9\xaa\x49\xf4\x1f\xb6\x22\x9e\xc0\x24\x33\xde\x09\x7c\x6c\x63\xce\xc7\x7c\x63\x61\x17\xf1\x71\x9a\xcc\x67\x9c\x5e\x85\xde\x51\xd4\xbe\x8a\x6d\xbf\xd3\xd3\x5c\xe3\xe1\xa4\x74\x2e\x12\xfc\x08\x21\xfc\xa9\x5e\xb7\xb0\xba\xbd\xf7\x67\xda\xa3\x82\x3b\xaf\x79\xeb\xdb\xae\xc2\xf2\xec\xdf\xb5\x5d\xb5\x13\x39\x70\x09\xcf\x9c\x17\x76\xd7\xf7\x83\xc2\xb1\x98\x94\xa6\x31\xe3\x94\x2c\xc3\x60\xbd\x48\xc5\x50\x26\x57\xb5\x3d\x3b\x65\xf9\x83\xa7\xdb\x14\x6e\x62\xe9\x8d\x94\x1a\xdf\x15\xd4\x48\x72\x29\xbe\xcf\x32\xb8\x97\x32\x9b\xd6\x04\x1d\xe4\xd5\xd0\x45\x9d\x54\x49\x87\x5e\x25\xb0\x0d\x27\xae\xcc\x96\x65\x27\x1d\x9e\x8a\xfe\xe9\x55\x8e\x4a\x45\x78\xcb\xf3\x6d\x66\x1b\x63\xbf\xd7\xa7\x4c\xbc\xa5\xe2\x54\xe6\x0e\xf0\x4a\xd9\xe2\xb3\xd8\xcc\x50\x58\x16\x3c\x9d\x2e\x9f\x36\x07\x4d\xb1\x38\x38\xae\xc7\xe5\x88\x85\xaa\x53\xe0\x8c\x63\xce\x32\x5f\xef\x71\x3a\x32\x9b\xc4\x72\x2c\x2e\x53\x31\xf4\x5f\xbf\xf1\x50\x89\x35\x52\xa9\xa8\xa6\x14\x5e\x2e\xeb\xe5\x4e\xc0\x07\x5b\x85\x5c\x8b\x5c\x30\xa5\x31\xf1\x5e\xef\x62\xa2\x87\x41\x08\x65\xd9\x8d\x0b\x9b\xcb\xe0\x97\xdf\x48\x69\xce\x05\xa2\x08\xde\xe3\xef\x5b\xae\x30\x71\xbb\x63\x26\xa0\x8d\x8a\xdd\x1a\xda\x6b\xec\xef\x4c\xdb\x43\x19\x57\x63\x8a\x86\xb6\xaa\x0f\x81\x35\xdb\x13\x4d\xa9\xe7\xd6\x15\x4e\x96\x9d\xc6\x6d\x0d\xfd\xa5\xb9\x3d\xce\x6f\x65\x46\xa5\xf1\x66\xc2\x96\xb6\x4d\xb0\x10\xae\x8e\x6b\x5b\x24\x6c\x3b\xf7\x7c\xc2\xfe\xae\x2f\x38\x44\x75\x2e\x0b\x53\xd9\x78\x01\xf3\x09\x3a\x4b\x40\x9a\xc9\xaa\x8e\x4c\xa1\xde\x66\x86\xb4\x36\x01\xdf\x74\x13\x56\xef\x2b\xa0\x53\xaa\x96\xc1\xfe\xa3\xc9\xea\x6e\x09\x36\x5c\x9d\x35\x2c\x23\x0d\xa2\x7e\xe4\x26\xde\xc0\x2e\xfc\x11\x9f\x5a\xcb\xe3\x1e\x78\xa6\x17\xd2\x5f\x4c\x5d\x6c\xd0\xb5\x5b\x59\x06\xab\x1a\xc0\x37\xea\x4e\xd6\xf0\x88\x2b\xec\x3b\x68\x96\xbe\x14\x86\x8b\x2d\x76\x36\xca\xce\xd3\x69\xa4\x2f\xc1\xa8\x1e\x19\x8f\x78\x18\x6b\xe7\x46\xee\x70\xde\x77\xbd\x45\x47\x65\xad\x78\x99\x8e\x99\x33\xe3\xe6\x9b\x7e\x27\xf5\x5b\xb6\x83\xe0\x0c\x97\xe5\x29\x7c\x77\xae\xaa\x7c\x7b\x3f\x15\xa3\xe5\xb2\xb9\x79\xa1\xf0\xaf\x8e\xb4\xd7\x2f\x7b\x9a\x03\xf4\xea\x97\xdf\xb4\x51\x5c\xac\xf7\x23\xa6\x84\xb2\x96\x06\x46\xda\x05\x7f\xba\x63\x7a\x09\x82\x67\x47\x8a\xa4\xeb\xf6\xa0\xb9\xc6\x38\xd4\xf1\xd5\x60\x76\xf4\x1c\x94\x4d\xef\xca\x2f\x31\x65\xdb\xcc\xd4\xd2\xbb\xc9\x90\x6b\x3a\x97\x36\x7c\x89\xa3\x64\xa4\x0b\x8c\x79\xca\x63\x60\xb6\x11\xb7\x14\x6c\xa1\x1c\xa7\xd1\x29\x94\xa3\x3d\x88\x65\xac\x73\x37\x33\xd1\x5d\xf8\x02\x3b\xe2\x30\xe3\x6e\x32\x45\xbe\x3f\x86\x74\x46\x89\x42\xc0\xc5\xee\xe0\xdd\xcd\xc0\x1e\x5f\x77\xc3\x52\x63\x1c\x69\x59\xfe\x88\xe6\xe4\xb4\xf6\xe4\xeb\x6c\x44\x8e\x70\xd6\x6b\xab\xff\x4f\x3a\xa4\xb9\x86\xe7\xf5\xe6\xe2\x7f\xb2\x5f\x8a\x22\xe0\xfa\x27\xa1\xb7\x45\x21\x95\xc1\xc4\x2a\x40\x61\x2c\x55\xa2\xe1\x71\x83\x66\x83\x0a\xe2\xad\x52\x28\x5c\xda\xa3\x50\xdb\x36\xf0\x61\x4d\x69\x48\x66\x75\x09\x29\xcb\x34\xce\x8e\x75\x67\xdf\x7a\xb0\xb3\x7b\x84\x51\x3e\x47\x1a\x87\x6f\xed\xd7\x1f\xa1\xda\x5e\xba\xfb\x4a\x34\x1b\x45\x70\x9d\xc2\x56\xa3\x02\x14\xec\x3e\x43\x57\x34\x77\x9e\x59\x2b\x80\xbf\x42\x5b\xc2\x23\x42\xcc\xa8\x0b\xd4\x23\x50\x36\x37\x72\x13\xf6\x99\xd7\x61\x75\x05\x17\xf6\xae\x7d\x3e\x7d\x9a\xd8\x6c\xb2\xd9\x89\x60\xe7\xa9\xe5\xb3\xbd\xe9\x4b\x7b\xd4\x89\x36\x1a\x66\xd1\x1e\x6f\x23\x8e\xe8\xbb\xd2\xd5\x79\x84\xca\x26\x2d\xd3\x94\x30\x84\xdf\x1f\x8e\x88\x16\xfe\x84\x63\x65\x52\x6a\x2a\x38\xfe\x2a\xb1\xe3\x5b\xb6\xe6\xf2\xb5\x90\xca\x15\xdd\xd6\xe1\x76\x90\x08\x67\xe3\x6e\x35\xbc\x74\xed\xba\xcc\xf0\x66\xd5\x17\xf9\xa3\xd2\x34\x46\x3f\x6b\xfc\xe9\x33\xbe\xa7\xc5\xd5\xae\xd3\x89\x47\x11\x5c\x6d\x30\x7e\x00\xd5\xb9\x83\x08\xbf\x4d\x73\xdd\xeb\xfb\xe6\x6d\xc6\x17\x9d\xe8\x4e\x1e\x84\xdc\x8b\xbb\x37\x32\xee\xa6\xee\xee\x8c\x94\xd1\xf6\x5d\xc5\xeb\xe4\xb4\x54\x6b\x23\xd3\x83\x77\xed\xc3\x17\x38\xc7\xc9\x8c\x5e\x1f\x1f\xd3\xe4\xe7\xce\x62\xa7\x8c\x62\xed\xd8\x72\x57\xe3\xbd\x97\x8b\xee\x25\x71\xf7\x15\xb1\x0d\xfb\x58\x21\x09\xcf\xc0\x7f\x38\x03\xf7\x4f\x55\x0e\x0b\xdb\x8d\xf5\x45\x21\xca\x72\xd1\x3a\x68\x6e\x2f\x9c\xc3\x1b\xa6\x58\xae\xc3\x5b\xeb\x94\x04\xe1\xd7\xdf\x5b\x2f\x6b\x6f\xb8\x30\x88\xcd\x47\x92\xc5\x9f\x16\xfe\x8d\xc5\x0f\x6b\x25\xb7\x22\xf1\xef\xd5\xbd\x93\xea\xb0\x39\xe9\x67\x6e\x36\x57\x0e\x7e\x1e\x9b\x8f\x4b\xe8\x9c\x7c\xc5\xb2\x0c\x15\x65\xf8\xbe\x2a\x5a\x78\x13\x5a\x39\x24\x5f\xef\xd4\x9a\x63\xbf\xd6\xe3\xe2\x64\xf9\x13\x4c\x51\x59\x1b\xcc\x17\xdd\xa6\xfb\xa2\x60\x66\x53\xd9\xd9\x93\xbd\x61\x66\xe3\x04\x1c\x09\x0f\x26\x12\x98\xe3\xef\x1e\x31\x08\x16\xfe\x49\x40\xe0\x5f\xb5\x07\x8b\x36\x1a\xd4\x13\x9a\xd9\xc0\x25\x04\xcb\x5f\x83\x5f\x83\xa0\x4f\xb8\x57\xcf\x50\x51\xb1\xd2\x61\x2a\x55\xce\x8c\xcd\x44\xf3\xc0\x89\x48\xbe\x58\x96\x81\x1d\x94\x1a\xc2\x65\x09\xfe\x93\x87\xf9\xa2\x09\xf9\xa9\x57\x5c\xae\x5a\x55\xfd\xcc\xa0\x3c\xd1\x80\x23\xa4\xf1\x95\x2c\x69\xaa\x15\x8b\x0d\x64\xfc\x01\xc1\x90\x4b\x37\x78\x1e\xbe\xf9\xa2\xc4\x0f\x45\x94\xad\x87\xcd\x4c\xa7\x76\x3d\x7b\x76\x10\x64\xb4\x7c\x39\xed\xbc\xc5\xc7\x1a\xec\xad\x34\xd7\xcd\xe1\xb5\xbe\x9a\xe0\x2d\xcb\x60\xd1\x2b\x08\x07\x72\x76\xf5\xf9\x03\xba\x29\xc1\x7d\x5c\x21\x13\x84\xa0\x9b\x97\x73\x5a\xab\x66\x89\x06\x6a\x98\x9e\x49\x11\x32\xa4\xcd\xf0\xda\x56\x2d\x8b\x59\x96\xf3\xc5\x40\xac\xba\x16\x35\x04\xaf\xc5\x8e\x65\xdc\x17\xa4\x57\x1f\x0b\x8c\xed\x37\x14\xb4\xd5\xa2\xb5\x84\xef\x63\xd2\xdd\x0a\xdc\x49\xfd\x7a\x7e\x40\x5e\x77\xf9\x73\x09\xac\x28\x50\x24\x76\x36\xd7\x4b\xd0\xa1\x4f\x49\xf6\xe2\xae\x95\x1a\xc2\x30\x74\xca\xdc\x31\x45\xd3\xf4\x54\x69\x75\xc4\x65\x61\x96\xb5\x43\x1f\xbc\x21\xb0\xe7\xd6\x1f\xfa\x10\xca\x77\x97\x54\x30\x07\xb5\xbc\xdd\x59\xf4\x52\x57\x93\xab\xaf\x58\x8e\x64\x80\x91\xec\xf5\x41\xf1\xfc\x0d\xd3\xc6\xa7\xb1\x57\x22\xa1\xb1\x7c\x73\x25\xf3\x9c\x95\x25\x71\xbc\x38\x50\xa4\xfb\xe5\xef\x50\xa5\x6e\xef\x8d\x15\x9a\x2a\x3b\x1c\x29\x36\x3e\x68\x8f\x16\x1c\x07\x57\x81\x9f\x5b\x78\x08\xed\xbf\x50\x7c\xfe\x13\x0f\x3b\xd9\xcb\xaa\xb4\xe6\xfa\x69\x7b\x89\x04\x8f\x1b\x9e\x21\x6c\x98\x48\x32\x2e\xd6\x60\xed\x46\x02\xfa\x4f\x82\x2a\x34\xeb\xa0\x77\x27\xbb\x67\xbf\xaf\xb4\x7c\x4f\xb8\xde\xd9\x5e\xe7\x1c\xbb\xed\x79\xd6\x20\x5c\x70\x53\xe7\x8a\x13\x3f\x10\xa2\xbf\x3a\x99\xbc\xc7\x35\xd7\x06\xd5\xd4\x5d\xba\x9a\xd3\xc8\xb6\xa4\xa4\x3a\x09\xb2\x18\x5e\x2c\xfe\x3b\x00\x00\xff\xff\xd1\x70\x3d\x62\x5e\x2c\x00\x00") +var _cmdDefinitionsTmplServiceTmpl = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\xec\x3a\x5b\x8f\xdb\x36\xd6\xef\xfe\x15\xa7\xc6\xa0\xb0\x03\x47\xfa\x3e\x60\x9f\xbc\xf0\x43\x77\x92\x66\x07\x4d\x93\x41\x26\xdd\x3e\xa4\xc5\x80\x96\x8e\x6c\xee\x48\xa4\x4a\xd2\x9e\x0c\x1c\xfd\xf7\xc5\x21\xa9\xbb\xe4\x4b\x36\x8b\x66\x17\x99\x97\x91\xc9\x73\xe7\xb9\x52\x0a\x43\xb8\x96\x31\xc2\x06\x05\x2a\x66\x30\x86\xf5\x13\x6c\x64\xf5\x1b\xf6\x9c\x41\x94\xc5\x61\x8c\x09\x17\xdc\x70\x29\xf4\x5f\xe1\xc5\x5b\x78\xf3\xf6\x3d\xbc\x7c\x71\xf3\x3e\x98\xe4\x2c\x7a\x60\x1b\x84\xc3\x01\x82\x37\x2c\x43\x28\x8a\xc9\x84\x67\xb9\x54\x06\x66\x13\x00\x80\x69\x24\x85\xc1\x8f\x66\xea\x7e\x71\x39\x9d\xb8\xa7\x0d\x37\xdb\xdd\x3a\x88\x64\x16\xae\xf1\x49\x8a\x58\x1b\xa9\xd8\x06\xc3\x8d\x7c\x5e\x3e\xee\xff\x12\xe6\x0f\x9b\x10\x45\x9c\x4b\x2e\x4a\x1a\x17\x60\x46\x0a\x63\x14\x86\xb3\xf4\x72\xdc\xad\x31\x79\x94\x72\xbc\x94\xaf\x46\xb5\xe7\x11\x6a\x87\x15\x9c\x8d\x67\x9e\x72\x42\x9a\x4f\x26\x7b\xa6\xe0\x1e\x6a\xd9\x83\x5b\x25\xf7\x3c\x46\xe5\x77\x4a\x7b\x04\xff\x60\xe9\x0e\xfd\xe2\x9d\xa3\x54\xc2\x94\x52\x04\x77\xee\xe1\xa5\x52\xb2\xdc\xab\x35\x0b\xde\xe6\xf6\x58\x27\x93\x30\x84\xf7\x4f\x39\x02\xd7\x60\xb6\x08\x24\x0c\x24\x52\xb5\x4e\x36\x92\x42\x1b\x07\xb6\x82\x69\x63\x67\x6a\xf1\xdf\xae\xff\x89\x91\xf9\x19\x0d\x8b\x99\x61\x40\xaa\xa1\x2e\x05\x81\xac\x5c\x27\xaa\xd2\x82\x06\x13\xcb\xa6\x87\xa7\x76\x91\x81\xc3\xe4\x70\x78\x0e\x8a\x89\x0d\xc2\xd5\xfd\x02\xae\xf6\xb0\x5c\x41\x70\x23\x12\xa9\x49\x18\x32\x2e\x41\xf0\x04\x84\x34\x70\xb5\x0f\x5e\xa5\x72\xcd\xd2\xe6\xde\x55\x2e\x48\xc0\xe5\x8a\xb6\xad\xac\x9f\xc0\xc8\x5b\xa6\xa3\x36\x1c\x4f\x08\xe0\x05\xd7\x79\xca\x9e\x4a\x6d\xc1\xff\x35\x08\xad\x46\xc0\x08\x04\x45\x5c\xff\xb4\x70\xa8\x23\xc5\xad\x7d\x9b\x1b\x8e\x52\x51\x78\x28\x6b\xcd\x3e\x99\xc6\x63\x61\x8d\xfb\x0a\x4d\xc7\x4e\x8f\x3c\x4d\x61\x83\xa6\x6b\xbf\x44\xc9\xcc\xaf\x05\x93\x30\x24\xe4\xe7\xf0\x7e\xcb\x35\x24\x3b\x11\x59\x71\xf4\x56\xee\xd2\xd8\xda\x6d\x8d\x10\xb1\x34\x75\xc1\x5f\x9e\x15\xcf\xf2\x14\x33\x14\x06\x55\x50\xe2\x23\x28\x34\x3b\x25\xb8\xd8\x74\x39\x72\x0d\x0a\x59\x0c\x52\xa4\x4f\xc0\x44\xdc\xa1\x9f\xc9\x98\x27\x1c\xe3\x60\x42\x02\xf4\x35\x99\x49\x78\xe6\x56\xe6\x5d\xca\x07\x6b\x17\x99\x2d\x40\x3e\xd0\x31\xca\xe0\x15\x1a\xef\xd1\x15\xfa\xdc\x02\xf1\x84\x60\x0e\xd5\xb1\x39\x69\x41\x66\xc1\xac\x4d\xd4\x81\x3b\x8b\x7b\xa0\x36\xc0\xa1\xb4\xb9\x1e\xb6\xb9\xee\xdb\x9c\x0b\x23\xcf\xb3\xb9\xb5\x51\x6d\x74\x29\x22\x5c\x40\x9e\x22\xd3\x08\x19\x7b\x40\xd0\x3b\x85\xc0\xd2\x14\x2c\xe1\x2d\xd3\xb0\x46\x14\xf0\xa8\xb8\x31\x28\x60\x8d\x89\x54\x48\x32\x78\x73\xf6\x84\xac\xcd\xb9\x80\xca\x13\x2a\xe5\x4b\x93\x06\x77\x7d\x43\xca\x6c\x4e\x9a\x0f\xc6\xdd\x2d\xe3\x4a\x97\x9e\x39\x14\x73\xe7\xc4\x5b\x1d\x6b\xd7\x52\x24\x29\x8f\x0c\xad\x86\x21\xbc\xc0\x5c\x61\x44\x35\x68\x09\xbf\x68\x84\x9c\xb8\x05\xbf\x72\xb3\x6d\x85\x0c\x17\xda\x20\x8b\xad\x89\x1b\x11\x12\x86\xd0\x03\xb5\x27\xc5\xf2\x3c\x7d\xf2\x81\xe6\xe3\x15\xf6\x94\x33\x81\x8e\xcb\xa5\x3e\x4f\x6c\x20\x62\xad\x79\xbb\x84\x67\xfb\x76\xe0\xce\x81\x2c\xd3\xf7\x3b\x5a\xad\x17\x7f\xc2\xa7\xa5\xcd\x98\xb5\x20\xd3\x45\xb5\x6b\xd3\xf8\x12\xf6\x0b\xef\x99\xad\xf0\x6f\x3c\xda\xf4\x4d\xa6\xf9\x99\xe5\xb0\x82\x8c\xe5\x1f\xb4\x51\x5c\x6c\x7e\x77\xff\xbc\x14\xc7\xcf\xef\x92\xdc\xd8\x91\xb8\x52\xc1\xeb\xee\x55\x68\xe7\xaa\x41\xee\x44\x41\xe7\x2c\xc2\x96\x08\x06\xb3\x3c\xa5\x46\x63\xca\x29\xd5\x24\xb4\x3f\xb5\x51\x70\x97\x52\x1a\x2a\x59\x5f\xed\x83\x9b\x0a\x60\x98\x40\x82\xcc\xec\xd4\x28\xfa\x8f\x3b\x11\x8d\x60\x92\x3d\xef\x05\x3e\x36\x31\x67\x43\x36\x99\xdb\x45\x7c\x1c\x27\xf3\x19\xdc\xcb\xf4\x70\x12\xb5\xe9\x06\xf4\x6c\x7b\xb2\x8e\xe5\xea\x28\x24\xa3\x73\x11\xe3\x47\x08\xe0\xff\xaa\x75\x0b\xab\x9b\x7b\xff\x4f\x7b\xe4\x55\xb3\x51\xcf\x29\xb1\xbc\xf8\xf7\xcd\x70\x6a\x79\x0c\xac\xe0\x7b\x17\x29\xed\xf5\x43\xaf\xb8\xcd\x47\xb5\xa9\x8f\x71\x4c\x97\x7e\x42\xb9\x4a\x44\x5f\x27\xd7\x59\x78\x71\x8a\xe2\x47\x4f\xb7\x6e\x2e\x48\xa4\xd7\x52\x6a\x7c\x9b\x53\xb3\xcb\xa5\xf8\x21\x4d\x61\x2d\x65\x3a\x6e\x09\x62\xe4\xcd\xd0\x46\x1d\x35\x49\x8b\x5e\xa9\xb0\x0d\x79\xae\xcc\x8e\xa5\x67\x31\x4f\x44\x97\x7b\x99\x47\x13\x11\xdc\xf1\x6c\x97\xda\xe6\xdd\xef\x75\x29\x93\x6c\x89\x38\x57\xb8\x23\xb2\x52\x06\xf9\x2c\x31\x53\x14\x56\x04\x4f\xa7\x2d\xa7\xcd\x93\x63\x22\xf6\xd8\x75\xa4\x1c\x38\xa1\x92\x0b\x5c\xc0\xe6\xa2\xe3\xeb\x65\xbc\x31\x5f\xae\x13\xcb\xa9\xb8\x4c\x44\xdf\x7f\xfd\xc6\x43\xa9\xd6\x40\x86\xa6\xba\x97\x7b\xbd\xac\x97\x3b\x05\x1f\x6c\xa5\x74\x6d\x7c\xce\x94\xc6\xd8\x7b\xbd\x8b\x89\x0e\x06\x21\x14\x45\x3b\x2e\x6c\x2e\x83\x0f\xbf\x93\xd1\x9c\x0b\x84\x21\xbc\xc3\x3f\x76\x5c\x61\xec\x76\x87\x8e\x80\x36\x4a\x71\x2b\x68\x6f\xb1\xbf\x33\x6d\x99\x32\xae\x86\x0c\x0d\x4d\x53\x1f\x03\xab\xb7\x47\x1a\x67\x2f\xad\x2b\xee\x2c\x3d\x4f\xda\x0a\xfa\x4b\x4b\x7b\x5a\xde\xf2\x18\x95\xc6\xdb\x91\xb3\xb4\xad\x8c\x85\x70\xbd\x86\xb6\x45\xc2\xb6\x9c\xcf\x46\xce\xdf\xf5\x2e\xc7\xa8\xce\x64\x6e\xca\x33\x9e\xc3\x6c\x84\xce\x02\x90\xe6\xc6\xb2\x6b\x54\xa8\x77\xa9\x21\xab\x8d\xc0\xd7\x1d\x8f\xb5\xfb\x12\x88\x4b\xd9\xd6\xd8\x7f\x34\xfd\xdd\x2f\xc0\x86\xab\x3b\x0d\x2b\x48\x8d\xa8\x1f\xb9\x89\xb6\xb0\x0f\x7e\xc2\xa7\xc6\xf2\xb0\x07\x5e\xe8\x85\xf4\x17\x51\xa7\x3d\x6d\x9f\x1b\xf5\x36\x15\x80\x1f\x26\x9c\xae\xc1\x09\x57\x38\xb4\xd0\x2c\x7d\x29\x0c\x17\x3b\x6c\x6d\x14\xad\x5f\xe7\x91\x5e\x81\x51\x1d\x32\x1e\xf1\x38\xd6\xde\x5d\x0b\x04\xb3\xae\xeb\xcd\x5b\x26\x6b\xc4\xcb\x78\xcc\x5c\x18\x37\xdf\xec\x3b\x6a\xdf\xa2\x19\x04\x17\xb8\x2c\x4f\xe0\xbb\x4b\x4d\xe5\x47\x90\xb1\x18\x2d\x16\xf5\xed\x10\x85\x7f\xc9\xd2\x5e\x11\x1d\x68\x56\xd1\xcb\x0f\x7e\xa4\x38\x0c\x1c\x25\x14\x95\x36\x30\xd0\x2e\x78\xee\x4e\xe8\x05\x08\x9e\x9e\x28\x92\xae\xdb\x83\x7a\x2e\x39\xd6\xf1\x55\x60\x76\x3c\xee\x95\x4d\xef\xca\x2f\x30\x61\xbb\xd4\x54\xda\xbb\xe9\x87\x6b\xe2\x4b\x1b\xbe\xc4\x51\x32\xd2\x39\x46\x3c\xe1\x11\x30\xdb\x88\x5b\x0a\xb6\x50\x0e\xd3\x68\x15\xca\xc1\x1e\xc4\x0a\xd6\xba\x3f\x1a\xe9\x2e\x7c\x81\x1d\x70\x98\x61\x37\x19\x23\xdf\x1d\x43\x5a\xa3\x44\x2e\xe0\x6a\x7f\xf4\x7e\xa9\x77\x1e\x5f\x77\xc3\x52\x61\x9c\x68\x59\xfe\x8c\xe6\xe4\xbc\xf6\xe4\xeb\x6c\x44\x4e\x48\xd6\x69\xab\xff\x47\x3a\xa4\x99\x86\x67\xd5\xe6\xfc\xbf\xb2\x5f\x0a\x43\xe0\xfa\x17\xa1\x77\x79\x2e\x95\xc1\xd8\x1a\x40\x61\x24\x55\xac\xe1\x71\x8b\x66\x8b\x0a\xa2\x9d\x52\x28\x5c\xda\xa3\x50\xdb\xd5\xf0\x41\x45\xa9\x4f\x66\xb9\x82\x84\xa5\x1a\x27\xa7\xba\xb3\x6f\x3d\xd8\xc5\x3d\xc2\xa0\x9c\x03\x8d\xc3\xb7\xf6\xeb\xcf\x30\x6d\x27\xdd\x7d\x25\x96\x0d\x43\xb8\x49\x60\xa7\x51\x01\x0a\xb6\x4e\xd1\x15\xcd\xbd\x17\xd6\x2a\xe0\xaf\xd0\x16\xf0\x88\x10\x31\xea\x02\xf5\x00\x94\xcd\x8d\xdc\x04\x5d\xe1\x75\x50\x5e\xc1\x05\x9d\x6b\x9f\x4f\x9f\x46\x36\xeb\x6c\x76\x26\xd8\x65\x66\xf9\x6c\x6f\xfa\xd2\x1e\x75\xe6\x19\xf5\xb3\x68\x47\xb6\x01\x47\xf4\x5d\xe9\xf2\x32\x42\x45\x9d\x96\x69\x4a\xe8\xc3\x1f\x8e\x47\x44\x03\x7f\xc4\xb1\x52\x29\x35\x15\x1c\x7f\x95\xd8\xf2\x2d\x5b\x73\xf9\x46\x48\xe5\x8a\x6e\x83\xb9\x1d\x24\x82\xc9\xb0\x5b\xf5\x2f\x5d\xdb\x2e\xd3\xbf\x59\xf5\x45\xfe\xa4\x36\xf5\xa1\x5f\x34\xfe\x74\x05\x3f\xd0\xe2\x72\xdf\xea\xc4\xc3\x10\xae\xb7\x18\x3d\x80\x6a\xdd\x41\x04\xdf\xa6\xb9\xf6\xf5\x7d\xfd\x36\xe3\x8b\x4e\x74\x67\x0f\x42\xee\xe5\xe2\x6b\x19\xb5\x53\x77\x7b\x46\x4a\x69\xfb\xbe\x94\x75\x74\x5a\xaa\xac\x91\xea\xde\xf7\x00\xfd\x17\x38\xa7\xc9\x0c\x5e\x1f\x9f\xb2\xe4\xe7\xce\x62\xe7\x8c\x62\xcd\xd8\x72\x57\xe3\x9d\x17\xa0\xee\x45\x76\xfb\x35\xb6\x0d\xfb\x48\x21\x29\xcf\xc0\x7f\xdc\x03\xeb\xa7\x32\x87\x05\xcd\xc6\xfa\x2a\x17\x45\x31\x6f\x30\x9a\xd9\x0b\xe7\xe0\x96\x29\x96\xe9\xe0\xce\x3a\x25\x41\xf8\xf5\x77\xd6\xcb\x9a\x1b\x2e\x0c\x22\xf3\x91\x74\xf1\xdc\x82\xbf\xb1\xe8\x61\xa3\xe4\x4e\xc4\xfe\xdd\xbf\x77\x52\x1d\xd4\x9c\x7e\xe5\x66\x7b\xed\xe0\x67\x91\xf9\xb8\x80\x16\xe7\x6b\x96\xa6\xa8\x28\xc3\x77\x4d\xd1\xc0\x1b\xb1\xca\x31\xfd\x3a\x5c\x2b\x89\xfd\x5a\x47\x8a\xb3\xf5\x8f\x31\x41\x65\xcf\x60\x36\x6f\x37\xdd\x57\x39\x33\xdb\xf2\x9c\x3d\xd9\x5b\x66\xb6\x4e\xc1\x81\xf0\x60\x22\x86\x19\xfe\xe1\x11\xa7\xd3\xb9\xff\x25\x60\xea\x3f\x07\x98\xce\x9b\x68\x50\x4d\x68\x66\x0b\x2b\x98\x2e\x7e\x9b\xfe\x36\x9d\x76\x09\x77\xea\x19\x2a\x2a\x56\x3a\x48\xa4\xca\x98\xb1\x99\x68\x36\x75\x2a\x92\x2f\x16\xc5\xd4\x0e\x4a\x35\xe1\xa2\x00\xff\x59\xc6\x6c\x5e\x87\xfc\xd8\x2b\x2e\x57\xad\xca\x7e\xa6\x57\x9e\x68\xc0\x11\xd2\xf8\x4a\x16\xd7\xd5\x8a\x45\x06\x52\xfe\x80\x60\xc8\xa5\x6b\x3c\x0f\x5f\x7f\xf5\xe2\x87\x22\xca\xd6\xfd\x66\xa6\x55\xbb\xbe\xff\xfe\x28\xc8\x60\xf9\x72\xd6\x79\x83\x8f\x15\xd8\x1b\x69\x6e\x6a\xe6\x95\xbd\xea\xe0\x2d\x8a\xe9\xbc\x53\x10\x8e\xe4\xec\xf2\x13\x0d\x74\x53\x82\xfb\x00\x44\xc6\x08\xd3\x76\x5e\xce\x68\xad\x9c\x25\x6a\xa8\x7e\x7a\x26\x43\xc8\x80\x36\x83\x1b\x5b\xb5\x2c\x66\x51\xcc\xe6\x3d\xb5\xaa\x5a\x54\x13\xbc\x11\x7b\x96\x72\x5f\x90\x5e\x7e\xcc\x31\xb2\xdf\x79\xd0\x56\x83\xd6\x02\x7e\x88\xc8\x76\x4b\x70\x9c\xba\xf5\xfc\x88\xbe\xee\xf2\x67\x05\x2c\xcf\x51\xc4\x76\x36\xd7\x0b\xd0\x81\x4f\x49\xf6\xe2\xae\x91\x1a\x82\x20\x70\xc6\xdc\x33\x45\xd3\xf4\x58\x69\x75\xc4\x65\x6e\x16\x95\x43\x1f\xbd\x21\xb0\x7c\xab\x8f\x91\x08\xe5\xbb\x15\x15\xcc\x5e\x2d\x6f\x76\x16\x9d\xd4\x55\xe7\xea\x6b\x96\x21\x1d\xc0\x40\xf6\x7a\xaf\x78\xf6\x9a\x69\xe3\xd3\xd8\x4b\x11\xd3\x58\xbe\xbd\x96\x59\xc6\x8a\x82\x24\x9e\x1f\x29\xd2\xdd\xf2\x77\xac\x52\x37\xf7\x86\x0a\x4d\x99\x1d\x4e\x14\x1b\x1f\xb4\x27\x0b\x8e\x83\x2b\xc1\x2f\x2d\x3c\x84\xf6\x1f\x28\x3e\xff\x8e\x87\x9d\xed\x65\x65\x5a\x73\xfd\xb4\xbd\x44\x82\xc7\x2d\x4f\x11\xb6\x4c\xc4\x29\x17\x1b\xb0\xe7\x46\x0a\xfa\xcf\x96\x4a\x34\xeb\xa0\xf7\x67\xbb\x67\xb7\xaf\xb4\x72\x8f\xb8\xde\xc5\x5e\xe7\x1c\xbb\xe9\x79\xf6\x40\xb8\xe0\xa6\xca\x15\x67\x7e\x20\x44\x7f\x55\x32\x79\x87\x1b\xae\x0d\xaa\xb1\xbb\x74\x35\xa3\x91\x6d\x41\x49\x75\x14\x64\x3e\x74\xe3\xd9\xe3\x70\x17\x6d\x31\x63\x9e\x9c\xff\xd6\x8a\xa2\xe9\x5f\x01\x00\x00\xff\xff\x63\x77\x96\xb0\x2d\x2d\x00\x00") func cmdDefinitionsTmplServiceTmplBytes() ([]byte, error) { return bindataRead( @@ -192,7 +192,7 @@ func cmdDefinitionsTmplServiceTmpl() (*asset, error) { } info := bindataFileInfo{name: "cmd/definitions/tmpl/service.tmpl", size: 0, mode: os.FileMode(0), modTime: time.Unix(0, 0)} - a := &asset{bytes: bytes, info: info, digest: [32]uint8{0x43, 0x8f, 0xb1, 0xb3, 0x7b, 0xd8, 0xc9, 0x2d, 0xcc, 0xd9, 0x7a, 0x9f, 0x9b, 0x19, 0xe2, 0x8d, 0x7b, 0xb5, 0x49, 0xbd, 0xe0, 0xb7, 0x85, 0x2c, 0x70, 0x3, 0x10, 0xba, 0xd1, 0x1d, 0xdd, 0x56}} + a := &asset{bytes: bytes, info: info, digest: [32]uint8{0x81, 0x50, 0x73, 0xce, 0x45, 0xd5, 0x2f, 0xe5, 0x55, 0x1b, 0x37, 0x53, 0x2b, 0x10, 0x52, 0xf4, 0x20, 0xb0, 0x79, 0x1, 0x7f, 0x9e, 0xa3, 0xed, 0xb1, 0xb0, 0x67, 0xe, 0x38, 0x4c, 0xdf, 0x88}} return a, nil } diff --git a/cmd/definitions/tests/connstr_test.go b/cmd/definitions/tests/connstr_test.go new file mode 100644 index 000000000..c5096f812 --- /dev/null +++ b/cmd/definitions/tests/connstr_test.go @@ -0,0 +1,137 @@ +package tests + +import ( + "errors" + "testing" + + "github.com/beyondstorage/go-storage/v4/pairs" + "github.com/beyondstorage/go-storage/v4/services" + . "github.com/beyondstorage/go-storage/v4/types" + "github.com/stretchr/testify/assert" +) + +func TestFromString(t *testing.T) { + cases := []struct { + name string + connStr string + pairs []Pair + err error + }{ + { + "empty", + "", + nil, + services.ErrConnectionStringInvalid, + }, + { + "simplest", + "tests://", + nil, + nil, + }, + { + "only options", + "tests://?size=200", + []Pair{ + pairs.WithSize(200), + }, + nil, + }, + { + "only root dir", + "tests:///", + []Pair{ + pairs.WithWorkDir("/"), + }, + nil, + }, + { + "end with ?", + "tests:///?", + []Pair{ + pairs.WithWorkDir("/"), + }, + nil, + }, + { + "stupid, but valid (ignored)", + "tests:///?&??&&&", + []Pair{ + pairs.WithWorkDir("/"), + }, + nil, + }, + { + "value can contain all characters except &", + "tests:///?string_pair=a=b:/c?d&size=200", + []Pair{ + pairs.WithWorkDir("/"), + WithStringPair("a=b:/c?d"), + pairs.WithSize(200), + }, + nil, + }, + { + "full format", + "tests://abc/tmp/tmp1?size=200&expire=100&storage_class=sc", + []Pair{ + pairs.WithName("abc"), + pairs.WithWorkDir("/tmp/tmp1"), + pairs.WithSize(200), + pairs.WithExpire(100), + WithStorageClass("sc"), + }, + nil, + }, + { + "duplicate key, appear in order (finally, first will be picked)", + "tests://abc/tmp/tmp1?size=200&name=def&size=300", + []Pair{ + pairs.WithName("abc"), + pairs.WithWorkDir("/tmp/tmp1"), + pairs.WithSize(200), + pairs.WithName("def"), + pairs.WithSize(300), + }, + nil, + }, + { + "not registered pair", + "tests://abc/tmp?not_a_pair=a", + nil, + services.ErrConnectionStringInvalid, + }, + { + "key without value is ignored (even not registered pair)", + "tests://abc/tmp?not_a_pair&&", + []Pair{ + pairs.WithName("abc"), + pairs.WithWorkDir("/tmp"), + }, + nil, + }, + { + "not parseable pair", + "tests://abc/tmp?io_call_back=a", + nil, + services.ErrConnectionStringInvalid, + }, + } + + for _, tt := range cases { + t.Run(tt.name, func(t *testing.T) { + servicer, err := services.NewServicerFromString(tt.connStr) + service, ok := servicer.(*Service) + + if tt.err == nil { + assert.Nil(t, err) + assert.True(t, ok) + } else { + assert.True(t, errors.Is(err, tt.err)) + return + } + + assert.Equal(t, service.Pairs, tt.pairs) + }) + } +} diff --git a/cmd/definitions/tests/service.go b/cmd/definitions/tests/service.go index 9d58e8e3e..a8827db96 100644 --- a/cmd/definitions/tests/service.go +++ b/cmd/definitions/tests/service.go @@ -10,6 +10,8 @@ type Service struct { defaultPairs DefaultServicePairs features ServiceFeatures + Pairs []Pair + UnimplementedServicer } diff --git a/cmd/definitions/tests/service.toml b/cmd/definitions/tests/service.toml index 721310e56..3c0eac2c7 100644 --- a/cmd/definitions/tests/service.toml +++ b/cmd/definitions/tests/service.toml @@ -74,4 +74,8 @@ description = "is the storage class for this object" [pairs.size] type = "int64" -description = "tests pair conflict" \ No newline at end of file +description = "tests pair conflict" + +[pairs.string_pair] +type = "string" +description = "tests connection string" \ No newline at end of file diff --git a/cmd/definitions/tests/utils.go b/cmd/definitions/tests/utils.go index e2e0dced2..160493a6f 100644 --- a/cmd/definitions/tests/utils.go +++ b/cmd/definitions/tests/utils.go @@ -19,7 +19,7 @@ func (s *Storage) String() string { } func NewServicer(pairs ...typ.Pair) (typ.Servicer, error) { - return nil, nil + return &Service{Pairs: pairs}, nil } func NewStorager(pairs ...typ.Pair) (typ.Storager, error) { diff --git a/cmd/definitions/tmpl/service.tmpl b/cmd/definitions/tmpl/service.tmpl index b5a8c988e..62bc358d2 100644 --- a/cmd/definitions/tmpl/service.tmpl +++ b/cmd/definitions/tmpl/service.tmpl @@ -73,6 +73,13 @@ func With{{ $pname }}(v {{ $v.Type }}) Pair { {{- end }} {{- end }} +var pairMap = map[string]string { + {{- range $_, $v := .Pairs }} + {{- $pname := $v.Name | toPascal }} + "{{ $v.Name }}": "{{ $v.Type }}", + {{- end }} +} + {{- range $_, $v := .Namespaces }} {{- template "interfaces" makeSlice $v.Name $v.Interfaces }} {{- template "features" makeSlice $v.Name $v.Funcs }} @@ -378,4 +385,5 @@ func init() { {{- range $_, $v := .Namespaces }} services.Register{{ $v.Name | toPascal }}r(Type, New{{ $v.Name | toPascal }}r) {{- end }} + services.RegisterSchema(Type, pairMap) } diff --git a/services/new.go b/services/new.go index a8baf0749..571916fff 100644 --- a/services/new.go +++ b/services/new.go @@ -1,8 +1,13 @@ package services import ( + "encoding/base64" + "fmt" + "strconv" + "strings" "sync" + "github.com/beyondstorage/go-storage/v4/pairs" "github.com/beyondstorage/go-storage/v4/types" ) @@ -14,8 +19,8 @@ type ( ) var ( - serviceFnMap map[string]NewServicerFunc - serviceLock sync.Mutex + servicerFnMap map[string]NewServicerFunc + servicerLock sync.Mutex storagerFnMap map[string]NewStoragerFunc storagerLock sync.Mutex @@ -23,18 +28,18 @@ var ( // RegisterServicer will register a servicer. func RegisterServicer(ty string, fn NewServicerFunc) { - serviceLock.Lock() - defer serviceLock.Unlock() + servicerLock.Lock() + defer servicerLock.Unlock() - serviceFnMap[ty] = fn + servicerFnMap[ty] = fn } // NewServicer will initiate a new servicer. func NewServicer(ty string, ps ...types.Pair) (types.Servicer, error) { - serviceLock.Lock() - defer serviceLock.Unlock() + servicerLock.Lock() + defer servicerLock.Unlock() - fn, ok := serviceFnMap[ty] + fn, ok := servicerFnMap[ty] if !ok { return nil, InitError{Op: "new_servicer", Type: ty, Err: ErrServiceNotRegistered, Pairs: ps} } @@ -64,6 +69,150 @@ func NewStorager(ty string, ps ...types.Pair) (types.Storager, error) { } func init() { - serviceFnMap = make(map[string]NewServicerFunc) + servicerFnMap = make(map[string]NewServicerFunc) storagerFnMap = make(map[string]NewStoragerFunc) } + +var ( + servicePairMaps map[string]map[string]string + schemaLock sync.Mutex +) + +// RegisterSchema will register a service's pair map. +// +// Users SHOULD NOT call this function. +func RegisterSchema(ty string, m map[string]string) { + schemaLock.Lock() + defer schemaLock.Unlock() + + servicePairMaps[ty] = m +} + +func NewServicerFromString(connStr string) (types.Servicer, error) { + ty, ps, err := parseConnectionString(connStr) + if err != nil { + return nil, InitError{Op: "new_servicer", Type: ty, Err: err, Pairs: ps} + } + return NewServicer(ty, ps...) +} + +func NewStoragerFromString(connStr string) (types.Storager, error) { + ty, ps, err := parseConnectionString(connStr) + if err != nil { + return nil, InitError{Op: "new_storager", Type: ty, Err: err, Pairs: ps} + } + return NewStorager(ty, ps...) +} + +var ( + // ErrConnectionStringInvalid means the connection string is invalid. + ErrConnectionStringInvalid = NewErrorCode("connection string is invalid") +) + +// ://[][][?key1=value1&...&keyN=valueN] +func parseConnectionString(ConnStr string) (ty string, ps []types.Pair, err error) { + colon := strings.Index(ConnStr, ":") + if colon == -1 { + err = fmt.Errorf("%w: %s, %s", ErrConnectionStringInvalid, "service type missing", ConnStr) + return + } + ty = ConnStr[:colon] + rest := ConnStr[colon+1:] + + schemaLock.Lock() + m, ok := servicePairMaps[ty] + schemaLock.Unlock() + if !ok { + err = ErrServiceNotRegistered + return + } + + if !strings.HasPrefix(rest, "//") { + err = fmt.Errorf("%w: %s", ErrConnectionStringInvalid, ConnStr) + return + } + rest = rest[2:] + + // [][][?key1=value1&...&keyN=valueN] + // does not contain '/' + // begins with '/' + question := strings.Index(rest, "?") + var path string + if question == -1 { + path = rest + rest = "" + } else { + path = rest[:question] + rest = rest[question+1:] + } + + if len(path) == 0 { + // both and missing + } else { + slash := strings.Index(path, "/") + if slash == -1 { + name := path + ps = append(ps, pairs.WithName(name)) + } else if slash == 0 { + workDir := path + ps = append(ps, pairs.WithWorkDir(workDir)) + } else { + name := path[:slash] + workDir := path[slash:] + ps = append(ps, pairs.WithName(name), pairs.WithWorkDir(workDir)) + } + } + + for _, v := range strings.Split(rest, "&") { + opt := strings.SplitN(v, "=", 2) + if len(opt) != 2 { + // && or &key&, ignore + continue + } + pair, parseErr := parse(m, opt[0], opt[1]) + if parseErr != nil { + ps = nil + err = fmt.Errorf("%w: %v", ErrConnectionStringInvalid, parseErr) + return + } + ps = append(ps, pair) + } + return +} + +func parse(m map[string]string, k string, v string) (pair types.Pair, err error) { + vType, ok := m[k] + if !ok { + err = fmt.Errorf("pair not registered: %v", k) + return types.Pair{}, err + } + + pair.Key = k + + switch vType { + case "string": + pair.Value, err = v, nil + case "bool": + pair.Value, err = strconv.ParseBool(v) + case "int": + var i int64 + i, err = strconv.ParseInt(v, 0, 0) + pair.Value = int(i) + case "int64": + pair.Value, err = strconv.ParseInt(v, 0, 64) + case "[]byte": + pair.Value, err = base64.RawStdEncoding.DecodeString(v) + default: + return types.Pair{}, fmt.Errorf("type not parseable: %v, %v", k, vType) + } + + if err != nil { + pair = types.Pair{} + err = fmt.Errorf("pair value invalid: %v, %v, %v: %v", k, vType, v, err) + } + return +} + +func init() { + servicePairMaps = make(map[string]map[string]string) +}