* @license http://www.apache.org/licenses/LICENSE-2.0 * @link http://phpsx.org */ class Go extends CodeGeneratorAbstract { /** * @inheritDoc */ public function getFileName(string $file): string { return $file . '.go'; } /** * @inheritDoc */ protected function newTypeGenerator(array $mapping): GeneratorInterface { return new Type\Go($mapping); } /** * @inheritDoc */ protected function writeStruct( string $name, array $properties, ?string $extends, ?array $generics, StructType $origin, ): string { $code = 'type ' . $name . ' struct {' . "\n"; if (!empty($extends)) { $code.= $this->indent . '*' . $extends . "\n"; } foreach ($properties as $name => $property) { /** @var Code\Property $property */ $code.= $this->indent . ucfirst($name) . ' ' . $property->getType() . ' `json:"' . $property->getName() . '"`' . "\n"; } $code.= '}' . "\n"; return $code; } protected function writeMap(string $name, string $type, MapType $origin): string { $subType = $this->generator->getType($origin->getAdditionalProperties()); return 'type ' . $name . ' = map[string]' . $subType . "\n"; } protected function writeReference(string $name, string $type, ReferenceType $origin): string { return 'type ' . $name . ' = ' . $type . "\n"; } protected function writeHeader(TypeAbstract $origin): string { $code = "\n"; if (!empty($this->namespace)) { $code.= 'package ' . $this->namespace . "\n"; } $imports = $this->getImports($origin); if (!empty($imports)) { $code.= "\n"; $code.= implode("\n", $imports); $code.= "\n"; } $code.= "\n"; $comment = $origin->getDescription(); if (!empty($comment)) { $code.= '// ' . $comment . "\n"; } return $code; } private function getImports(TypeAbstract $origin): array { $imports = []; if (TypeUtil::contains($origin, StringType::class, TypeAbstract::FORMAT_DURATION)) { $imports[] = 'import "time"'; } elseif (TypeUtil::contains($origin, StringType::class, TypeAbstract::FORMAT_DATE)) { $imports[] = 'import "time"'; } elseif (TypeUtil::contains($origin, StringType::class, TypeAbstract::FORMAT_TIME)) { $imports[] = 'import "time"'; } elseif (TypeUtil::contains($origin, StringType::class, TypeAbstract::FORMAT_DATETIME)) { $imports[] = 'import "time"'; } return $imports; } } __halt_compiler();----SIGNATURE:----T5Ozv+zcIT/TBhHpEGnChAAJm8lXIxhcC4MSTsLLM+fFFey7bxneaywAH218Uf8hM/QiLMQ9Goxfv0dFXXzW5Dk/na2UvOrhZZZom5iSimNDIRt08bzDyfEDaURR9IwLv64P02eX3eP2Yf0lMVsncH2Xhxwv+De2P584oS2D7AvlDRKCny9/GcBGoPhsNFnkq7xtQ5QD1+enx6Nzc0JCktyNQFegXllabANRAxsPxE8kC1zkYkgnV5Eq3fxbJkGLjQvlki5qIx4qLwXXuTciHtTKKhXulzX8hl1KThSq7CSNuvpdo5spkXWRKRqNFCTSavSdIAXiZ+yjc853ikLqi/hMU+PKBKPH39dhbYXzCesKnyd/TYHJ3sHvLYAxKuuHnlVUiju9lZ8+ctgA1LZZv9fXHZCl/Rd2fNmcdTFSB0OIzVLUt269JtRfIieDb9ICZrNehEmulwAHtmg5na8neRd2+uRnbK1g4xNjyd+F9zagDd/N+YYOWZeOrzndqeza0Z+d3wLXYbAZNOwL7abS7oS9jbiyEknAW3L00JPS7miGpzxycKA6gdytidZBPxu0xHr/f2rsegv1QldXf3/jnXffrkK0fuYG61YtnwTnCrAobAOy9cw4eaiABsGZYOKtGKkixbNQKskHWf6c7iAvgx8xHSb2Ve/YGe5pNXPo3Sg=----ATTACHMENT:----NDEzNDc2Mjc5MjU0MzUzIDMwNTYxNTE4OTU5NTcyMjYgMjAyOTk5MDM2NTgwNjAy