Segwit transaction in golang I tried to create transaction which spends p2sh(p2wpkh) output:


from wif I derived compressed pub key: "035476e55521c97cf0489e6c57893a99d67e84d306a69e6b6904f324c11b3cef8d".
created witness program: "813798fcae182d1a36c6b4bb5f69e03bb9ec4124".
created script: "0014813798fcae182d1a36c6b4bb5f69e03bb9ec4124" and sigscript from script which should be specified to spend this ouput: "160014813798fcae182d1a36c6b4bb5f69e03bb9ec4124".
added tx input: {hash: "863fea23ba1c176bda5e360b0be25cacc405877aa3e46a3e1c60196c3b6cd7b6", vout: 0, signatureScript: scriptSig, witeness: nil}
created pkscript for address "14s9ocrbTX3ZCybtcN1jmtdxxJwKuyM3Em" (p2sh-p2wpkh): "a914809800f62119afdcf2317882eda5efd7a9a2163487". 
added txout {amount: 11000, scriptPubKey: pkscript}
calculated txSigHashes := txscript.NewTxSigHashes(tx)
decoded utxo subscript into bytes: "a914bb4d332112bde9787ac2da5954ee5a2c5fbada6987".
derived witness signature: wit := txscript.WitnessSignature(tx, txSigHashes, 0, amount, subscript, txscript.SigHashAll, wif.PrivKey, true)
result: "3045022100bae83fd9e87751350a09bc4c120b29decadb13fb389541c3025a8982906602d5022005dc688901fd27b749cfd4ce14a62587f267a070984654271454e88cc3f9ed4e01 035476e55521c97cf0489e6c57893a99d67e84d306a69e6b6904f324c11b3cef8d".
added witness signature to tx.TxIn[0].Witness
Serializied signed tx: "01000000000101b6d76c3b6c19601c3e6ae4a37a8705c4ac5ce20b0b365eda6b171cba23ea3f860000000017160014813798fcae182d1a36c6b4bb5f69e03bb9ec4124ffffffff01f82a000000000000434104b2534d287f2d9fa908319557298591143fecbd3f6497d6d11f283b80c3248c35f580ff376805418c3610256bc102c0beb3e9f745d493aed81127f5d4a4921bebac02483045022100bae83fd9e87751350a09bc4c120b29decadb13fb389541c3025a8982906602d5022005dc688901fd27b749cfd4ce14a62587f267a070984654271454e88cc3f9ed4e0121035476e55521c97cf0489e6c57893a99d67e84d306a69e6b6904f324c11b3cef8d00000000"


Even if I followed all the rules to create this transaction any try to push it into mainnet (via Blockcypher and other services) failed because of this error: "Error validating transaction: Error running script for input 0 referencing 863fea23ba1c176bda5e360b0be25cacc405877aa3e46a3e1c60196c3b6cd7b6 at 0: Script was NOT verified successfully"

So my question is where have I wrong done? Which step is wrong and how to do it in a right way?
I found that witness didn't include serializied script: that func for some reason just ingnored writing script into buffer, that means algorithm specified here(https://github.com/bitcoin/bips/blob/master/bip-0143.mediawiki, specification paragraph) ignored 5th step. So I removed if statement, and instead of (https://github.com/btcsuite/btcd/blob/master/txscript/script.go#L496) pasted writing has160 of pub key and that worked for me